Hello Lukas,
Thanks for the reply.
I have narrowed down my problem - For whatever reason, the lost of the WiFi signal did not raise an "ftp.upload" exception in my code (my understanding is that it will - from this thread ->
http://forum.rebex.net/4873/sftp-problemdetected-upload-exception-handling ). This is really strange.
I have attached the main parts of my code as follows. If you could spare some time to have a look, maybe I made an error somewhere.
private void TransferLogFiles()
{
if (ftp.State != FtpState.Disconnected)
return;
ftpWorker = new Thread(new ThreadStart(FtpWorkerThread));
Extensions.SetThreadPriority(ftpWorker, (int)settings.Priorities.FTP);
ftpWorker.IsBackground = true;
ftpWorker.Start();
}
private void FtpWorkerThread()
{
try
{
FileSet fileSet = new FileSet(settings.LogManager.TransferFolder);
fileSet.Include("*.csv", TraversalMode.MatchFilesShallow);
fileSet.Include("*.log", TraversalMode.MatchFilesShallow);
fileSet.Include("*.hscsr", TraversalMode.MatchFilesShallow);
LocalItemCollection files = fileSet.GetLocalItems();
if (files.Count == 0)
log.Warn("No files in transfer folder: Nothing to upload to FTP!");
else
{
log.Info("Trying to connect to FTP server {0}:{1} with username \"{2}\" and password \"{3}\"", settings.LogManager.FTP.Address, settings.LogManager.FTP.Port, settings.LogManager.FTP.User, settings.LogManager.FTP.Password);
ftp.Timeout = settings.LogManager.FTP.Timeout * 1000;
ftp.Connect(settings.LogManager.FTP.Address, settings.LogManager.FTP.Port);
ftp.Login(settings.LogManager.FTP.User, settings.LogManager.FTP.Password);
ftp.TransferMode = FtpTransferMode.Zlib;
ftp.TransferType = FtpTransferType.Binary;
if (!ftp.DirectoryExists(settings.LogManager.FTP.RemoteFolder))
ftp.CreateDirectory(settings.LogManager.FTP.RemoteFolder);
foreach (LocalItem file in files)
{
log.Info("Uploading \"{0}\" to FTP server", file.Name);
ftp.Upload(file.FullPath, settings.LogManager.FTP.RemoteFolder, TraversalMode.MatchFilesShallow, Rebex.IO.TransferMethod.Copy, Rebex.IO.ActionOnExistingFiles.ResumeIfPossible);
MoveToBackup(file.FullPath);
}
}
}
catch (FtpException e)
{
log.Error("Error transferring files to FTP: \"{0}\"", e.Message);
}
finally
{
ftp.Disconnect();
}
}