FTP component timing out after 40 minutes

0 votes
asked Apr 13, 2013 by Rebex KB (8,130 points)
edited Apr 13, 2013

We use Rebex FTP component to download files from FTP server. In our code we didn’t set the timeout property for connection.

I just wanted to know, what is the default timeout for a FTP connection. As I can see from the logs this connection is getting timed out after around 40 minutes. But I searched and the default timeout should be 60 seconds.

Could you please help me to increase this timeout period up to 1 hour?

Here is an excerpt from the log:

2013-03-18 15:37:17.670 INFO Ftp(1) Command: TYPE I
2013-03-18 15:37:17.763 INFO Ftp(1) Response: 200 Type set to I.
2013-03-18 15:37:17.779 INFO Ftp(1) Command: SIZE .
2013-03-18 15:37:17.888 INFO Ftp(1) Response: 550 .: not a plain file.
2013-03-18 15:37:17.888 INFO Ftp(1) Command: SIZE 'FILE NAME'
2013-03-18 15:37:18.013 INFO Ftp(1) Response: 213 1925070955
2013-03-18 15:37:18.028 DEBUG Ftp(1) Info: Starting data transfer.
2013-03-18 15:37:18.028 DEBUG Ftp(1) Info: Accepting data connection.
2013-03-18 15:37:18.044 INFO Ftp(1) Command: PORT 'PORT'
2013-03-18 15:37:18.340 INFO Ftp(1) Response: 200 PORT command successful.
2013-03-18 15:37:18.340 INFO Ftp(1) Command: RETR 'FILE NAME'
2013-03-18 15:37:18.558 INFO Ftp(1) Response: 150 Opening BINARY mode data connection for 'FILE NAME'
2013-03-18 15:37:18.589 DEBUG Ftp(1) Info: Data connection accepted from 'IP ADDRESS'
2013-03-18 16:17:01.225 INFO Ftp(1) Info: Timing out.
2013-03-18 16:17:01.225 ERROR Ftp(1) Info: Error while reading data: Rebex.Net.FtpException: Timeout exceeded.
   at Rebex.Net.Ftp.QztfFZ()
   at wWGvS.bEcmRk.BMJzdYZ(Byte[] , Int32 , Int32 )
   at wWGvS.bEcmRk.Read(Byte[] buffer, Int32 offset, Int32 count)
2013-03-18 16:17:01.225 DEBUG Ftp(1) Info: Data connection failed.
2013-03-18 16:17:01.225 ERROR Ftp(1) Info: Rebex.Net.FtpException: Timeout exceeded.
   at Rebex.Net.Ftp.QztfFZ()
   at wWGvS.bEcmRk.BMJzdYZ(Byte[] , Int32 , Int32 )
   at wWGvS.bEcmRk.Read(Byte[] buffer, Int32 offset, Int32 count)
   at wWGvS.bsWOwAZ.Read(Byte[] buffer, Int32 offset, Int32 count)
   at Rebex.Net.Ftp.bjMtzmZ(String , Boolean , Stream , Int64 , String )

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered Apr 13, 2013 by Tomas Knopp (58,580 points)
edited Apr 13, 2013
 
Best answer

Thank you for the log file. It looks like some firewall might have blocked the connection after 40 minutes.

Here is a short explanation why increasing the timeout would not help in your case:

The default timeout in Rebex Ftp component is indeed 60 seconds. However, the counter is reset when a packet is received. So in your case a long-running transfer was running for 40 minutes (split into many packets, each time a packet was received the counter was reset, so no timeout occcured, which is correct). But then at 16:17:01.225 a packet was not received after 60 seconds (for the first time) and so the timeout correctly triggered. The packet was blocked by a buggy router along the way.

Please try the KeepAliveDuringTransfer option. This will send a NOOP command in a specified interval which will prevent the firewall from blocking packets. The option can be enabled like this:

                Ftp ftp = new Ftp();
                ftp.Settings.KeepAliveDuringTransfer = true;

                ftp.Connect("server", port);
                ftp.Login("user", "password");

                // do work

                ftp.Disconnect();

If you still get the timeout with this option enabled, experimenting with ftp.KeepAliveDuringTransferInterval might help (default interval is 600000ms = 10minutes) which can be further decreased.

...