Below is my code. Or any suggestion or correction would be greatly appreciated. thanks.
using (Session session = new Session())
{
// Will continuously report progress of synchronization
session.FileTransferred += FileTransferred;
// Connect
session.Open(sessionOptions);
//string stamp = DateTime.Now.ToString("yyyyMMdd", CultureInfo.InvariantCulture);
//string fileName = "export_" + stamp + ".txt";
//string remotePath = "/home/user/sysbatch/" + fileName;
//string localPath = @"d:\backup\" + fileName;
string fileName = remotefileName + "*" + remotefileExte;
string remotePath = remotefolder;
//string localPath = remoteGoAnyWherefolder;
string localPath = remotearchivefolder;
//// You can achieve the same using:
//session.SynchronizeDirectories(
// SynchronizationMode.Local, localPath, remotePath, false, false,
// SynchronizationCriteria.Time,
// new TransferOptions { FileMask = fileName }).Check();
var diffs = session.CompareDirectories(
SynchronizationMode.Local, localPath, remotePath, false, false,
SynchronizationCriteria.Time,
new TransferOptions { FileMask = fileName });
if (diffs.Count>0)
{
foreach (ComparisonFileInfo fileInfo in diffs)
{
string extension = Path.GetExtension(fileInfo.FileName);
if (string.Compare(extension, remotefileExte, true) == 0)
{
//Console.WriteLine("Adding {0} to listing", fileInfo.Name);
// Download files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult = session.GetFiles(fileInfo.FileName, remoteGoAnyWherefolder, false, transferOptions);
// Throw on any error
transferResult.Check();
}
}
}
}