FTP Upload Resume Disconnection Notification
Hi Friend ,Resume is working Fine .While internet disconnected want to show message .From session.PutFiles giving no notifications
static void Main(string[] args)
{
try
{
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "SERVER_URL",
UserName = "USERNAME",
SshPrivateKeyPath = @"C:\PuttyPrivateKey.ppk",
SshHostKeyPolicy = SshHostKeyPolicy.GiveUpSecurityAndAcceptAny,
Timeout = new TimeSpan(0, 0, 15)
};
using (Session session = new Session())
{
session.FileTransferProgress += SessionFileTransferProgress;
session.SessionLogPath = @"C:\connection_loss_log_1.log";
// Connect
session.Open(sessionOptions);
if (!session.FileExists(fileToDownload))
{
Console.WriteLine("File does not exist!");
session.Close();
}
else
{
RemoteFileInfo remoteFileInfo = session.GetFileInfo(fileToDownload);
remoteFileSize = remoteFileInfo.Length;
// Download files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
string fullDestPath = Path.Combine(destinationPath, fileToDownload);
TransferOperationResult transferResult = session.GetFiles(fileToDownload, fullDestPath, false, transferOptions);
// Throw on any error
transferResult.Check();
session.Close();
}
}
}
catch (SessionLocalException sle)
{
Console.WriteLine("SessionLocalException " + sle.Message);
}
catch (SessionRemoteException sre)
{
Console.WriteLine("SessionRemoteException " + sre.Message);
}
catch (Exception ex)
{
Console.WriteLine("Error in ProcessEdi() while downloading EDI files via FTP: Message:" + ex.Message + "Stacktrace: " + ex.StackTrace);
}
Console.WriteLine("End.");
Console.ReadLine();
}
static void SessionFileTransferProgress(object sender, FileTransferProgressEventArgs e)
{
long currentSize = (long)(remoteFileSize * e.FileProgress);
Console.WriteLine("Progress: " + currentSize +" of " + remoteFileSize);
Console.WriteLine("OVerallProgress: " + e.OverallProgress);
Console.WriteLine("==========================");
}
Session.SessionLogPath
. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.Session.GetFiles()
and Session.GetFileToDirectory()
.
GetFiles
does have the Check()
method to throw any errors, but it does not seem to do anything.