【发布时间】:2015-07-31 14:56:13
【问题描述】:
使用 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();
【问题讨论】:
-
这有点受欢迎,所以我想添加评论。我升级到最新版本的 sshnet 库,所有超时问题都已解决。