Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: session.CompareDirectories

You didn't tell us, what problem are you facing.

And, why don't you use Session.SynchronizeDirectories, if you want to synchronize the directories, rather than comparing them?
jamgodz

session.CompareDirectories

Hi Experts,

I really need some help, on how to download file from the Session.CompareDirectories.
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();
            }
        }
    }
}