FluentFTP: when upload big file(11g db backup file), timed out trying to read data from the socket stream!

**FTP OS: winserver2016

**FTP Server:filezilla0.9.60

**Computer OS:winserver 2012

it doesn’t happen when upload small file. when upload a big(test on 200mb & 10gb) db backup file, client.UploadFile(localFullFilePath, ftpFullPath) method report a timeout exception.The Error is "Timed out trying to read data from the socket stream! " the wield thing is the db file is actual uploaded, i check the file size in ftp is right(but not check the file content). so i think may be after upload big file, the flutent ftp does something read, which cause this error.

FluentFTP.FtpException: Error while uploading the file to the server. See InnerException for more info. —> System.TimeoutException: Timed out trying to read data from the socket stream! 在 FluentFTP.FtpSocketStream.Read(Byte[] buffer, Int32 offset, Int32 count) 在 FluentFTP.FtpSocketStream.ReadLine(Encoding encoding) 在 FluentFTP.FtpClient.GetReply() 在 FluentFTP.FtpClient.UploadFileInternal(Stream fileData, String remotePath, Boolean createRemoteDir, FtpExists existsMode, Boolean fileExists, Boolean fileExistsKnown, IProgress1 progress) --- 内部异常堆栈跟踪的结尾 --- 在 FluentFTP.FtpClient.UploadFileInternal(Stream fileData, String remotePath, Boolean createRemoteDir, FtpExists existsMode, Boolean fileExists, Boolean fileExistsKnown, IProgress1 progress) 在 FluentFTP.FtpClient.UploadFileFromFile(String localPath, String remotePath, Boolean createRemoteDir, FtpExists existsMode, Boolean fileExists, Boolean fileExistsKnown, FtpVerify verifyOptions, IProgress1 progress) 在 FluentFTP.FtpClient.UploadFile(String localPath, String remotePath, FtpExists existsMode, Boolean createRemoteDir, FtpVerify verifyOptions, IProgress1 progress)

(000001)2019/3/28 12:50:03 - scims (192.168.163.1)> OPTS UTF8 ON (000001)2019/3/28 12:50:03 - scims (192.168.163.1)> 202 UTF8 mode is always enabled. No need to send this command. (000001)2019/3/28 12:50:03 - scims (192.168.163.1)> SYST (000001)2019/3/28 12:50:03 - scims (192.168.163.1)> 215 UNIX emulated by FileZilla (000001)2019/3/28 12:50:07 - scims (192.168.163.1)> PWD (000001)2019/3/28 12:50:07 - scims (192.168.163.1)> 257 “/” is current directory. (000001)2019/3/28 12:50:07 - scims (192.168.163.1)> SIZE /r2012.jpg (000001)2019/3/28 12:50:07 - scims (192.168.163.1)> 550 File not found (000001)2019/3/28 12:50:07 - scims (192.168.163.1)> TYPE I (000001)2019/3/28 12:50:07 - scims (192.168.163.1)> 200 Type set to I (000001)2019/3/28 12:50:07 - scims (192.168.163.1)> EPSV (000001)2019/3/28 12:50:07 - scims (192.168.163.1)> 229 Entering Extended Passive Mode (|||61165|) (000001)2019/3/28 12:50:07 - scims (192.168.163.1)> STOR r2012.jpg (000001)2019/3/28 12:50:07 - scims (192.168.163.1)> 150 Opening data channel for file upload to server of “/r2012.jpg” (000001)2019/3/28 12:54:48 - scims (192.168.163.1)> disconnected. (000001)2019/3/28 12:54:48 - scims (192.168.163.1)> 226 Successfully transferred “/r2012.jpg” (000001)2019/3/28 12:54:48 - scims (192.168.163.1)> could not send reply, disconnected.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 34 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I solved it this way…

int progress = -1;
try
{
   FtpClient client = new FtpClient("HOST");
   client.Credentials = new NetworkCredential("USER", "PASSWORD");
   client.Connect();

   client.UploadFile("LOCALPATH/FILENAME", "REMOTEPATH/FILENAME",
       FtpExists.Overwrite,
       false,
       FtpVerify.None,
       new Progress<FtpProgress>(p => progress = Convert.ToInt32(p.Progress))
       );
}
catch (Exception ex)
{
   if (progress == 100 && ex is FluentFTP.FtpException && ex.InnerException != null && ex.InnerException is TimeoutException)
   {
       // Upload complete
       // LOG Info exception
   }
   else
   {
       // LOG Fatal exception
       throw;
   }
}

Hi.

I updated to FluentFTP 28.0.2 from NuGet.

I downloaded a 3.46 GB file, but still received the same exception:

FluentFTP.FtpException: Error while downloading the file from the server. See InnerException for more info. ---> System.TimeoutException: Timed out trying to read data from the socket stream!
   at FluentFTP.FtpSocketStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at FluentFTP.FtpSocketStream.ReadLine(Encoding encoding)
   at FluentFTP.FtpClient.GetReply()
   at FluentFTP.FtpClient.DownloadFileInternal(String remotePath, Stream outStream, Int64 restartPosition, Action`1 progress)
   --- End of inner exception stack trace ---
   at FluentFTP.FtpClient.DownloadFileInternal(String remotePath, Stream outStream, Int64 restartPosition, Action`1 progress)
   at FluentFTP.FtpClient.DownloadFileToFile(String localPath, String remotePath, FtpLocalExists existsMode, FtpVerify verifyOptions, Action`1 progress)
   at FluentFTP.FtpClient.DownloadFile(String localPath, String remotePath, FtpLocalExists existsMode, FtpVerify verifyOptions, Action`1 progress)

Thank you.

I migrated my code from System.Net.FtpWebRequest to FluentFTP, thinking it would solve this issue. I get this error when downloading large files. I took the suggestion from https://stackoverflow.com/a/48983508/90287.

I recommend trying client.SocketKeepAlive = true; to see if that resolves the issue.

Here are the code comments for DataConnectionType:

Data connection type, default is AutoPassive which tries a connection with EPSV first and if it fails then tries PASV before giving up. If you know exactly which kind of connection you need you can slightly increase performance by defining a specific type of passive or active data connection here.

The log in the original post indicated that the client connected using EPSV.

Someone indicated that updating their FileZilla server resolved the issue.

Thank you.

Edit Setting client.SocketKeepAlive = true; did not resolve the issue.

I also tried setting client.ReadTimeout = -1; and client.ReadTimeout = Int32.MaxValue; but then the download method didn’t return after the file was downloaded.

@robinrodricks, that worked! 🎉

FluentFTP 29.0.3 no longer throws a TimeoutException when downloading a large file (3.53 GB).

Thank you very much! 😃

@icnocop @robinrodricks Test finished: I have a upload method inside a .dll created for me, the first StackTrace is the Main method which I call the upload method. The 2nd Stacktrace is the main interest:

StackTrace

1. In Main.cs One or more errors occurred. (Error while uploading the file to the server. See InnerException for more info.)

at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at Aleiser_ECS_Gral_Function_Test.Program.Main(String[] args) in D:\Documents\Visual Studio 2019\Projects\Aleiser ECS Gral Function Test\Main.cs:line 39

2. This exception has an InnerException that is the StackTrace that throws upload method: Timed out trying to read data from the socket stream! | System.Exception {System.TimeoutException}

at FluentFTP.FtpSocketStream.<ReadAsync>d__68.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at FluentFTP.FtpSocketStream.<ReadLineAsync>d__71.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at FluentFTP.FtpClient.<GetReplyAsync>d__179.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at FluentFTP.FtpClient.<UploadFileInternalAsync>d__153.MoveNext()

InnerException 1: FtpException: Error while uploading the file to the server. See InnerException for more info.

InnerException 2: TimeoutException: Timed out trying to read data from the socket stream!

Code:

Main.cs

        static void Main(string[] args)
        {
            UploadTaskFTP u = new UploadTaskFTP(Server, User, Pass);
            // SetGUIProgressUpdatesFTP() is returning an Progress object, to report in the console the upload percent
            u.FtpUploadFileAsync(@"D:\Downloads\ubuntu.iso", "/directory/to/upload", SetGUIProgressUpdatesFTP()).Wait();
        }

Upload method:

        public async Task FtpUploadFileAsync(string filePath, string dirTo, IProgress<FtpProgress> progress)
        {
            FtpClient client = new FtpClient(Server);
            this.progress = progress;
            string remoteFilePath = string.Format(
                "{0}/{1}", dirTo, (filePath.Split(Path.DirectorySeparatorChar).Reverse()).ElementAt(0));

            try
            {
                if (File.Exists(filePath))
                {
                    client.Credentials = new NetworkCredential(User, Pass);
                    await client.ConnectAsync();

                    if (await client.DirectoryExistsAsync(dirTo))
                    {
                        await client.UploadFileAsync(filePath, remoteFilePath, progress: progress);
                    }
                    else
                    {
                        throw new Exception($"Directory {dirTo} doesn't exist. Please try another to upload.");
                    }
                }
                else
                {
                    throw new FileNotFoundException($"File {filePath} doesn't exist or is used by another process.");
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (client.IsConnected)
                    await client.DisconnectAsync();
            }
        }

I hope this will guide to a solution.

Test finished:

  • File size: 1.9 GB (ubuntu .iso)
  • Port: 21
  • Action: Upload file

Sorry, the problem about TimeoutException still exists 😦 @robinrodricks

Still exist

@stefanolazzarato thanks for this fix, I finally understood the problem! I’ve attempted to absorb all TimeoutExceptions during upload/download if the file is fully transferred in the latest version https://www.nuget.org/packages/FluentFTP/27.1.4

@stefanolazzarato @wjchristenson2 @icnocop @nicojmb @luchunminglu Can everyone test the latest version and see if you are still getting those pesky errors?