Home Forums .NET libraries Xceed SFTP/FTP for .NET Uploading files in a loop throws timeout exception

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #21292 |

    Hi

    I am using Xceed.Ftp.dll (4.1.10075.13300) for a following scenario…We have a need to upload multiple files, one at the time to FTP server. After uploading few files, however, a timeout occurs with following exception (see log output) …There are 5-10 files (FileInfo) that payload holds as part of the PayloadItem…If I use an external FTP client there are no problems…During testing the FTP server is installed on the same local machine as the client…All files are empty (0 bytes)….

     

    Here is the output of the log file from connection to point of failiure…

    2010-03-16 21:29:01,640 DEBUG TestFtpClient >>> Attempting connection to FTP server hostname: [localhost], port [21], username: [test_user], password: [**********]…
    2010-03-16 21:29:01,687 DEBUG TestFtpClient >>> Server <– [220-FileZilla Server version 0.9.34 beta
    220-written by Tim Kosse (Tim.Kosse@gmx.de)
    220 Please visit http://sourceforge.net/projects/filezilla/%5D
    2010-03-16 21:29:01,703 DEBUG TestFtpClient >>> Server <– [331 Password required for test_user]
    2010-03-16 21:29:01,703 DEBUG TestFtpClient >>> Client –> [USER test_user]
    2010-03-16 21:29:01,703 DEBUG TestFtpClient >>> Client –> [PASS **********]
    2010-03-16 21:29:01,703 DEBUG TestFtpClient >>> Server <– [230 Logged on]
    2010-03-16 21:29:01,718 DEBUG TestFtpClient >>> Client –> [TYPE I]
    2010-03-16 21:29:01,718 DEBUG TestFtpClient >>> Server <– [200 Type set to I]
    2010-03-16 21:29:01,718 DEBUG TestFtpClient >>> Client –> [PASV]
    2010-03-16 21:29:01,718 DEBUG TestFtpClient >>> Server <– [227 Entering Passive Mode (127,0,0,1,4,249)]
    2010-03-16 21:29:01,718 DEBUG TestFtpClient >>> Sending file [C:\TestFtpClient\bin\Debug\data\T20100316012000.txt]
    2010-03-16 21:29:01,718 DEBUG TestFtpClient >>> Client –> [STOR T20100316012000.txt]
    2010-03-16 21:29:01,734 DEBUG TestFtpClient >>> Server <– [150 Connection accepted]
    2010-03-16 21:29:01,734 DEBUG TestFtpClient >>> Server <– [226 Transfer OK]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Server <– [200 Type set to I]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Client –> [TYPE I]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Client –> [PASV]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Server <– [227 Entering Passive Mode (127,0,0,1,4,251)]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Sending file [C:\TestFtpClient\bin\Debug\data\T20100316012201.txt]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Client –> [STOR T20100316012201.txt]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Server <– [150 Connection accepted]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Server <– [226 Transfer OK]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Client –> [TYPE I]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Server <– [200 Type set to I]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Client –> [PASV]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Server <– [227 Entering Passive Mode (127,0,0,1,4,253)]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Sending file [C:\TestFtpClient\bin\Debug\data\T20100316012230.txt]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Client –> [STOR T20100316012230.txt]
    2010-03-16 21:29:01,750 DEBUG TestFtpClient >>> Server <– [150 Connection accepted]
    2010-03-16 21:29:01,765 DEBUG TestFtpClient >>> Server <– [226 Transfer OK]
    2010-03-16 21:29:01,781 DEBUG TestFtpClient >>> Client –> [TYPE I]
    2010-03-16 21:29:01,781 DEBUG TestFtpClient >>> Server <– [200 Type set to I]
    2010-03-16 21:29:01,781 DEBUG TestFtpClient >>> Client –> [PASV]
    2010-03-16 21:29:01,781 DEBUG TestFtpClient >>> Server <– [227 Entering Passive Mode (127,0,0,1,4,255)]
    2010-03-16 21:29:01,781 DEBUG TestFtpClient >>> Sending file [C:\TestFtpClient\bin\Debug\data\T20100316012300.txt]
    2010-03-16 21:29:01,781 DEBUG TestFtpClient >>> Client –> [STOR T20100316012300.txt]
    2010-03-16 21:29:01,781 DEBUG TestFtpClient >>> Server <– [150 Connection accepted]
    2010-03-16 21:29:01,781 DEBUG TestFtpClient >>> Server <– [226 Transfer OK]
    2010-03-16 21:29:01,781 DEBUG TestFtpClient >>> Client –> [TYPE I]
    2010-03-16 21:29:01,781 DEBUG TestFtpClient >>> Server <– [200 Type set to I]
    2010-03-16 21:29:31,796 ERROR TestFtpClient >>> Error while uploading file [C:\TestFtpClient\bin\Debug\data\TT20100316010300.txt] to FTP server! Message: [The FTP command execution timed-out.]
    2010-03-16 21:29:31,812 ERROR TestFtpClient >>> Full Stacktrace:
       at Xceed.Ftp.Engine.FtpCommandSequence.EndExecute(IAsyncResult asyncResult)
       at Xceed.Ftp.FtpClient.DoExecuteCommand(FtpCommandChannel commandChannel, BaseFtpCommand command)
       at Xceed.Ftp.FtpClient.DoSendFile(FtpCommandChannel commandChannel, SendFileFtpCommandSequence sequence)
       at Xceed.Ftp.FtpClient.SendFile(String localFilename)
       at TestFtpClient.Send(IPayload payload) in C:\TestFtpClient\TestFtpClient.cs:line 67
    2010-03-16 21:29:31,843 DEBUG TestFtpClient >>> Client –> [TYPE I]
    2010-03-16 21:29:31,843 DEBUG TestFtpClient >>> Server <– [200 Type set to I]
    2010-03-16 21:30:01,859 ERROR TestFtpClient >>> Error while uploading file [C:\TestFtpClient\bin\Debug\data\TT20100316010900.txt] to FTP server! Message: [The FTP command execution timed-out.]
    2010-03-16 21:30:01,875 ERROR TestFtpClient >>> Full Stacktrace:
       at Xceed.Ftp.Engine.FtpCommandSequence.EndExecute(IAsyncResult asyncResult)
       at Xceed.Ftp.FtpClient.DoExecuteCommand(FtpCommandChannel commandChannel, BaseFtpCommand command)
       at Xceed.Ftp.FtpClient.DoSendFile(FtpCommandChannel commandChannel, SendFileFtpCommandSequence sequence)
       at Xceed.Ftp.FtpClient.SendFile(String localFilename)
       at TestFtpClient.Send(IPayload payload) in C:\TestFtpClient\TestFtpClient.cs:line 67

     

    Here is the code we are using:

                FtpClient client = new FtpClient();

                try
                {
                    client.Connect(_hostname, _port);
                    client.Login(_username, _password);

                    foreach(IPayloadItem pi in payload.Items)
                    {
                        // If for any reason ftp upload fails, reset transported boolean to false
                        // so that file is not deleted and is re-transported on the next job run…
                        try
                        {
                            client.SendFile(pi.Data.FullName);   // NOTE: IPayloadItem.Data is of type FileInfo
                            pi.Transported = true;
                        }
                        catch (Exception e)
                        {
                            _log.Error(m => m(“Error while uploading file [{0}] to FTP server! Message: [{1}]”, pi.Data.FullName, e.Message));
                            _log.Error(m => m(“Full Stacktrace:\n{0}”, e.StackTrace));
                            pi.Transported = false;
                        }     
                    }
                }
                catch (FtpException e)
                {
                    _log.Error(m => m(“Error while connecting to FTP server! Message: [{0}]”, e.Message));
                }
                finally
                {
                    try
                    {
                        client.Disconnect();
                    }
                    catch { }
                }   

    Can anyone suggest as to what may be the issue?

    Thanks

    Z…

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by zambak (had 1973 views)

    Xceed Support
    Member
    Post count: 5658

    Hi,

    It seems that you are connecting very often for a small period of time (All the timestamps are more or less at 2010-03-16 21:29:01)

    Also, when you receive the error, the reply of the PASV command is not received; this implies that there no more available TCP ports on the server and that the majority are in TIME_WAIT to ensure determining the connection before its reuse; which entails that the DataChannel will no longer be capable of connecting, and hence, no more data transfer.

    It is a problem caused by the server and not the library. If you want to configure your server to decrease the TIME_WAIT, you can see how to do it here: http://zeeky.mzrahman.com/archives/000019.html.

    Can you try to use 2 Mb files instead of 0 bytes? Does it solve your problem?

     

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Alain [Xceed] (had 351 views)

    User (Old forums)
    Member
    Post count: 23064

    You are correct – we have been using 0 size files for testing…But there is only 8-10 of them and the server is on the same machine as the client…Is it possible that 10 transfers can take up all TCP ports?

    We expect to have some 0 size files which do have to be transferred (business requirement). Most files we hope will be in range of 50 KB – 2 MB…

    I will try larger files and report back 

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by zambak (had 280 views)

    User (Old forums)
    Member
    Post count: 23064

    Update:

    I did the test with several non-zero size files (ranging from 50KB – 2MB) and I am still seeing timeouts..I also used TcpView from sysinternals to monitor ports and their statuses…During transfer, I only see 2 ports in TIME_WAIT status for entire system and they disappear in few seconds…..

    I also tried setting PassiveTransfer to false and lovering KeepAliveInterval (to 10) and increasing Timeout (to 45) to no avail…

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by zambak (had 427 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    From the post http://xceed.com/CS/forums/thread/26149.aspx I have noticed that the last file (“[C:\TestFtpClient\bin\Debug\data\T20100316012230.txt], in the log”) is transfered twice.  The timeout exception comes out right after. 

    1) I would investigate why the file T20100316012230.txt is sent twice.

    2) You should set the propert PassiveTransfer to true.  There is no gain in having the PassiveTransfer set to false. 

    — IF AND ONLY IF 1) and 2) are unsuccessful then :

    3) The character, “SendTelnetInterruptSignal”, should *NOT* be sent.  According to the RFC 959 (http://www.faqs.org/rfcs/rfc959.html), it is recommended to send this signal before sending the ABOR, STAT, and QUIT commands.  It is not required, but recommended.  The RFC also mentions that if a server does not support it, it should not “react” to it, i.e. do a timeout exception, in this case. 

    However, there is a workaround.  You can use the SendCustomCommand to send the command.  This way the telnet signal, will not be sent.

    Here is a quote from the RFC :

      FTP commands may be partitioned as those specifying access-control
      identifiers, data transfer parameters, or FTP service requests.
      Certain commands (such as ABOR, STAT, QUIT) may be sent over the
      control connection while a data transfer is in progress.  Some
      servers may not be able to monitor the control and data connections
      simultaneously, in which case some special action will be necessary
      to get the server’s attention.  The following ordered format is
      tentatively recommended:

          1. User system inserts the Telnet “Interrupt Process” (IP) signal
          in the Telnet stream.

          2. User system sends the Telnet “Synch” signal.

          3. User system inserts the command (e.g., ABOR) in the Telnet
          stream.

          4. Server PI, after receiving “IP”, scans the Telnet stream for
          EXACTLY ONE FTP command.

      (For other servers this may not be necessary but the actions listed
      above should have no unusual effect.)

    4) Don’t change KeepAliveInterval.  It should be to the minimal, i.e. 0, therefore not interefering with the FTP session.

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Ghislain (had 2682 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.