SFTP upload using sshnet library - Handling connection problems

Using the Renci sshnet library, I cannot handle connection issues when uploading a file.

If I set a breakpoint on UploadFile, disconnect my connection and let it run, it just hangs at that line. These are potentially large files on slow connections, so adding an OperationTimeout would be difficult.

Plus, it works great and consistently on serial connections. Any ideas? Thank!

AuthenticationMethod[] methods = new AuthenticationMethod[1];
methods[0] = new PasswordAuthenticationMethod(username, pwd);

var con = new ConnectionInfo(Config.RemoteHostName, username, methods);
con.Timeout = new TimeSpan(0, 0, 0, 30);
var client = new SftpClient(con);

client.Connect();

string fullFilePath = string.Format("{0}{1}", Config.RemoteFilePath, filename);
client.BufferSize = 15000;
client.UploadFile(new MemoryStream(buffer), fullFilePath);
client.Disconnect();

      

+3


source to share


1 answer


When transferring files, The SftpClient.OperationTimeout

determines how long the library waits for a read / write operation in one buffer (by default 64 KB max, see SftpClient.BufferSize

). Not how long he waits for a complete transmission.



So you can safely change it from the default "infinite" to some meaningful value.

+4


source







All Articles