2


I am using Renci.Ssh.Net to upload file at SFTP location.

           using (SftpClient client = new SftpClient(host, port, sftpUser, sftpPassword))
            {
                client.Connect();
                if (client.IsConnected)
                {
                    client.BufferSize = 1024;
                    var filePath = sftpDir + fileName;

                    client.UploadFile(memoryStream, filePath, (o) =>
                    {
                       isUploaded = true;
                    });

                    client.Disconnect();
                }
                client.Dispose();
            }

How can I verify if file is successfully uploaded?UploadFile() function's 3rd parameter is callback action.I tried to print the bytes (o) inside callback, but it seems UploadFile() uploads bytes in chunks,not all bytes at once, so I found bytes to be printed multiple times.
How can I use callback to verify successful upload?
Thanks.

Priya
  • 1,375
  • 8
  • 21
  • 45
  • yes, o is number of bytes sent in a chunk. I tried doing that but total count was mismatched. I need to send the content from MemoryStream. So I tried comparing memoryStreamObject.Length and total bytes. But they were not matching. – Priya Mar 11 '19 at 17:20

1 Answers1

0

There's no point abusing the uploadCallback to check, if the file uploaded correctly.

If anything goes wrong SftpClient.UploadFile method throws an exception. If it does not throw, the upload succeeded. Handling callback won't give you more confidence.


See also How to perform checksums during a SFTP file transfer for data integrity?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992