session.CompareDirectories

Advertisement

jamgodz
Joined:
Posts:
1
Location:
Philippines

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();
            }
        }
    }
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,603
Location:
Prague, Czechia

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?

Reply with quote

Advertisement

You can post new topics in this forum