sshnet / sshnet/SSH.NET

SSH.NET - Socket read operation has timed out after 30000 milliseconds.

Open
#889 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

Hi @drieseng I'm getting issue also on my SFTP setup using the SSH.NET latest version using .NET 5.0. It works fine until I got this issue.

Socket read operation has timed out after 30000 milliseconds.

This is my current code.

using (SftpClient sftpClient = new SftpClient(await getSftpConnection(export.Schedule.Host,
export.Schedule.Username,
export.Schedule.Password,
export.Schedule.KeyFile,
export.Schedule.Parapharase,
export.Schedule.LogonType, log)))

    {
        try
        {
            if (!sftpClient.IsConnected)
            {
                log.LogInformation($"Connecting Sftp....");
                do
                {
                    try
                    {
                        sftpClient.Connect();
                    }
                    catch (Renci.SshNet.Common.SshConnectionException e)
                    {
                        log.LogInformation($"Connection error: {e.Message}");
                    }
                } while (!sftpClient.IsConnected);

                log.LogInformation($"Done connecting Sftp");
            }
                    //Send file per devicename
                    foreach (var _perDevice in export.ExportTablePerDevice)
                    {
                        log.LogInformation($"Device {_perDevice.DeviceName}");
                        try
                        {
                            var csv = export.Schedule.Layout.Equals("LAYOUT 05") ? ReportHelper.ConvertToDat(export.ExportTable) :
                                ReportHelper.ConvertToCsv(_perDevice.ExportTable, export.Schedule.Layout, _perDevice.TopUserHeader);

                            var stream = ZipArchiveExtensions.GenerateStreamFromString(csv);

                            string filename = "";
                            if (export.IsExportDevices)
                            {
                                filename = _perDevice.DeviceName.Replace(@"/", "_") + "_" + DateTime.Now.Ticks + "." + export.Schedule.ExportFormat.ToLower() ?? "csv";
                            }
                            else
                            {
                                    filename = (!String.IsNullOrEmpty(export.Schedule.FileName) ? export.Schedule.FileName.Replace(@"/", "_").Replace("#tick", DateTime.Now.Ticks.ToString()) :
                                       _perDevice.DeviceName.Replace(@"/", "_") + DateTime.Now.Ticks) + "." + export.Schedule.ExportFormat.ToLower() ?? "csv";
                            }
                            var file = $"/{export.Schedule.FilePath}/{filename}";
                            await sftpClient.UploadAsync(stream, file);
                        }
                        catch (Exception ex)
                        {
                            sftpClient.Disconnect();
                            sftpClient.Dispose();
                            log.LogInformation($"Device error: {ex.Message}");
                        }
                    }
            sftpClient.Disconnect();
            response = new StatusCodeResponse()
            {
                Code = HttpStatusCode.OK.ToString(),
                HttpStatus = (int)HttpStatusCode.OK,
                Message = $"Successfully sent export {export.Schedule.Name} via sftp server"
            };

        }
        catch (Exception ex)
        {
            sftpClient.Disconnect();
            log.LogInformation($"An exception has been caught {ex.Message}");
            response = new StatusCodeResponse()
            {
                HttpStatus = (int)HttpStatusCode.InternalServerError,
                Code = HttpStatusCode.InternalServerError.ToString(),
                Message = $"Error sending export {export.Schedule.Name} via sftp server: {ex.Message}"
            };
        }
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied C# example, focusing on SftpClient.Connect and UploadAsync around the reported 30-second socket read timeout. Reproduce the failure with the described .NET 5.0 SFTP setup and determine the server, connection, or upload conditions that trigger it; no repository file or test is named, so completion criteria are not yet defined.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.