0

I am using WinSCP .NET assembly to transfer files from Windows to Unix server (mostly .doc files). Sometimes the file is transferred as blank document. But the source has come content in it. I can't go for directory level synchronization because am transferring documents to Unix server from different client machines. I am using the following code:

SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Ftp,
    HostName = cls_appvars.Set_FTP_Host,
    UserName = cls_appvars.Set_FTP_User,
    Password = cls_appvars.Set_FTP_Password,
};

using (Session session = new Session())
{                   
    session.Open(sessionOptions);

    TransferOptions transferOptions = new TransferOptions();
    transferOptions.TransferMode = TransferMode.Binary;

    TransferOperationResult transferResult;

    transferResult = session.GetFiles(wordfilepath, downloadwordpath + ".tmp", false, transferOptions);

    System.IO.File.Move(downloadwordpath + ".tmp", downloadwordpath);

    transferResult.Check();   

    foreach (TransferEventArgs transfer in transferResult.Transfers)
    {
        System.IO.File.AppendAllText(path, System.DateTime.Now + "***func_download_file_individual() in scribeapp*** Download succeeded for file " + transfer.FileName + Environment.NewLine);
    }

    session.Abort();
    session.Dispose();
}

Is there any way to check on the transferred file is synchronized with the source file?

Martin Prikryl
  • 147,050
  • 42
  • 335
  • 704
Suressh
  • 15
  • 7

1 Answers1

0

With an appropriate support on the server, you can use the Session.CalculateFileChecksum to calculate checksum of the uploaded file. Compare that to a checksum of the source file to verify the upload was successful.

For a complete example see Verify checksum of a remote file against a local file over SFTP/FTP protocol (it's in PowerShell, but it should be easy to translate it to C#).

Though a correct solution would be to find out, why is the upload is failing in the first place.


Do not use the .Abort() method, unless in an exceptional situation. Also no point or using the .Dispose(), as you are at the end of the using block that calls the .Dispose() implicitly.

Martin Prikryl
  • 147,050
  • 42
  • 335
  • 704
  • Thanks for your suggestion martin. let me try and let you know, in the first place FTP is not failing the file was successfully uploaded without any exception but there is no content in it. – Suressh Jan 05 '15 at 15:39