简体   繁体   中英

Compare local and remote files on FTP with WinSCP lib

How i can check updates via WinSCP on FTP server with .NET?

I'm using SynchronizationMode.Local

For example:

if(have_new_update){
    MessageBox("U can update")
    if(ok){
        update();
    }
}else{
    return;
}

My code:

SessionOptions sessionOptions = new SessionOptions {
    Protocol = Protocol.Ftp, HostName = ftp_url, UserName = username, Password = pass
};
using (Session session = new Session()) {
    rtb_update_material.AppendText("\nConnected\n");
    //Transferring
    session.FileTransferred += FileTransferred;
    session.FileTransferProgress += SessionProgressBar;
    session.Open(sessionOptions);
    SynchronizationResult synchronizationResult;
    synchronizationResult = session.SynchronizeDirectories(SynchronizationMode.Local, @"MyPath\", "/", true);

    synchronizationResult.Check();
    if (synchronizationResult.IsSuccess)
        rtb_update_material.AppendText("Done\n");

Use Session.CompareDirectories to find the differences between a local and a remote directory:

var diffs =
    session.CompareDirectories(SynchronizationMode.Remote, localPath, remotePath, false);

if (diffs.Count > 0) 
{
    // there are differences
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM