Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

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

gajus

Re: Syncing actively written host

Hi Martin, this seems to help. Thanks.
gajus

Syncing actively written host

Hi,

I'm trying to synchronize with a remote FTP host which is actively writing files to the remotePath. See code below:
using (Session session = new Session())
{
    // Will continuously report progress of synchronization
    // Also copy to Syncdir after download 'File' is ready
    session.FileTransferred += FileDownload;
 
    // Will continuously report progress of transfer
    session.FileTransferProgress += FileTransferProgress;
 
    SessionOptions sessionOptions = new SessionOptions()
    {
        Protocol = Protocol.Ftp,
        HostName = Host,
        PortNumber = PortNumber,
        UserName = User,
        Password = Password
    };
 
    // Connect
    session.Open(sessionOptions);
 
    // Synchronize files from remote to destination (local)
    SynchronizationResult synchronizationResult = session.SynchronizeDirectories(
        SynchronizationMode.Local,
        LocalPath,
        RemotePath,
        false,
        false,
        SynchronizationCriteria.Size,
        new TransferOptions { ResumeSupport = new TransferResumeSupport() { State = TransferResumeSupportState.Smart } }
    );
 
    // Throw on any error
    synchronizationResult.Check();
 
    session.Close();
}


This code will report:
WinSCP.SessionRemoteException: Error transferring file 'file.txt'.

Copying files from remote side failed.
file.txt: No such file or directory
at WinSCP.OperationResultBase.Check()
at

Where file.txt is the actively written file by the remote host.

I'm wondering if there is any way to tell session.SynchronizeDirectories to ignore files which are actively being written or perhaps there is a different way to handle this situation?