使用 Renci 的 sshnet 库,我无法在上传文件时处理连接问题。
如果我在 UploadFile 上设置断点,禁用我的连接并让它运行,它就会挂在该行上。这些可能是慢速连接上的大文件,因此添加 OperationTimeout 会很困难。
此外,这在一致的连接上一遍又一遍地工作。有任何想法吗?谢谢!
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();