C# SFTP SSH.NET套接字读取操作在30000毫秒后超时
我将文件上传到 SFTP 时收到随机错误。假设我有 100 个文件要上传,其中 90-95 个文件加载成功,其余 4-5 个文件抛出错误,如下所示。不确定是什么导致了这个问题。下面是代码。它在 client.Connect(); 步骤失败
错误消息:FileUpload 存储库错误:Renci.SshNet.Common.SshOperationTimeoutException:套接字读取操作在 30000 毫秒后超时。在Renci.SshNet.Abstractions.SocketAbstraction.Read(Socket套接字,Byte []缓冲区,Int32偏移量,Int32大小,TimeSpan超时)
int port = 8022;
if (int.TryParse(portString, out port))
{
using (var client = new SftpClient(host, port, username, pd))
{
client.Connect();
if (!client.IsConnected)
{
throw new Exception("connection to the SFTP failed");
}
client.ChangeDirectory(FinalFolder);
using (var fs = new FileStream(sourcefile, FileMode.Open))
{
client.BufferSize = 4 * 1024;
client.UploadFile(fs, Path.GetFileName(sourcefile));
fs.Close();
}
}
I am receiving random errors when uploading my file to SFTP. Say I have 100 files to upload, out of which 90-95 files are loading successful and rest 4-5 files are throwing error as below. Not sure what is causing the issue. Below is the code. It is failing at the step client.Connect();
Error Message: FileUpload Repository Error: Renci.SshNet.Common.SshOperationTimeoutException: Socket read operation has timed out after 30000 milliseconds. at Renci.SshNet.Abstractions.SocketAbstraction.Read(Socket socket, Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
int port = 8022;
if (int.TryParse(portString, out port))
{
using (var client = new SftpClient(host, port, username, pd))
{
client.Connect();
if (!client.IsConnected)
{
throw new Exception("connection to the SFTP failed");
}
client.ChangeDirectory(FinalFolder);
using (var fs = new FileStream(sourcefile, FileMode.Open))
{
client.BufferSize = 4 * 1024;
client.UploadFile(fs, Path.GetFileName(sourcefile));
fs.Close();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论