C# SFTP SSH.NET socket read operation has timed out after 30000 milliseconds
Under taker
1
Reputation point
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();
}
}
Sign in to answer