WinSCP - Uploading files from Windows machine to Linux - Error: Timespan overflowed because the duration is too long

WinSCP - Uploading files from Windows machine to Linux - Error: Timespan overflowed because the duration is too long

我从 Managed NuGet 包安装了 WinSCP。

我正在尝试使用 WinSCP 将文件从 Windows 上传到 Linux 服务器。我收到错误

Timespan overflowed because the duration is too long.

我已尝试使用以下代码上传文件。

public int Upload(
    String HostName, String UserName, String Password, String remotePath,
    String localFilePath)
{
    int result = 0;
    Session session = null;
    try
    {
        // Setup session options               
        SessionOptions sessionOptions = new SessionOptions
        {
            Protocol = Protocol.Ftp,
            HostName = HostName,
            UserName = UserName,
            Password = Password,
            Timeout = TimeSpan.MaxValue,
        };

        using (session = new Session())
        {
            // Connect
            session.Open(sessionOptions);

           // upload files
            TransferOptions transferOptions = new TransferOptions();
            transferOptions.TransferMode = TransferMode.Ascii;

            TransferOperationResult transferResult = null;

            transferResult =
                session.PutFiles(localFilePath, remotePath, false, transferOptions);

            // Throw on any error
            transferResult.Check();
            // Print results
            foreach (TransferEventArgs transfer in transferResult.Transfers)
            {
                Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
            }

        }

        result = 0;
    }
    catch (Exception e)
    {
        Console.WriteLine("Error: {0}", e);
        result = 1;
    }
    finally
    {
        if (session != null)
        {
            session.Dispose();
        }
    }
    return result;
}

如何上传文件到远程服务器?

收到的堆栈异常是:

at System.TimeSpan.Add(TimeSpan ts) 
at System.TimeSpan.op_Addition(TimeSpan t1, TimeSpan t2)
at WinSCP.Session.CheckForTimeout(String additional) 
at WinSCP.PatientFileStream.Wait(Int32& interval) 
at WinSCP.PatientFileStream.Read(Byte[] array, Int32 offset, Int32 count) 
at System.Xml.XmlTextReaderImpl.ReadData() 
at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars) 
at System.Xml.XmlTextReaderImpl.ParseText() 
at ProjectName.Upload(String HostName, String UName, String Password, String remotePath, String localFilePath)

SessionOptions.Timeout 设置为一些实际值:

Timeout = TimeSpan.FromDays(1),