Free Support Forum - aspose.com

FTP connection forcibly closed

I have posted about this in the past, and it was never resolved so I thought I would try again. I am connecting to a UNIX ProFtpd server and sending queries on the file size of many files. I am receiving the following error:

Aspose.Network.Ftp.FtpException was unhandled
Message="Receive command failed:Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
Source="Aspose.Network"

My initial process was

1. Create a connection
2. Call sub procedure to check the file size
3. In sub, check to see if the connection is open, if not then open it.
4. Check the file size and return it to the calling procedure.

After receiving the above error I modified it to

1. Call sub procedure to check the file size
2. In sub, close any existing connection, create a new instance of FtpClient and open that new instance.
3. Check the file size and return it to the calling procedure.

I am still receiving the error message above. The error occurs when I check to see if the file exists before running a query on it's size.

If _ftp.Connected Then
_ftp.Disconnect()
End If

_ftp = New Aspose.Network.Ftp.FtpClient("myhost", "username", "password")

_ftp.Connect(True)

If Me._ftp.Exists(filename) Then 'Error occurs on this line

'Do work here

End If

Please look into this and let me know what you find. Thanks!

Hello,

Please check this thread.

What thread would that be?

Hello, dthayer,

It looks like the remote server closed the connection. How's the size of the file? I am doing some investigation on it. If the size of the file is quit large, the server may close the connection if we do not ping it.

I will get back to your shortly.

Thanks

I am not downloading any files, I am just checking file sizes.

As a temporary fix I am using the ListDirectoryDetails() method and then looping through in my code until I find the file name the matches. I do not run into the "forcibly closed" error this way, but it is not ideal either.

I will contact our host and see if there is a reason why they might be closing the connection (too many requests perhaps?). Please continue your research in the meantime.

In case it helps you reproduce the problem, our host is using ProFtpd on Unix.

Thanks!

Dan

I think it is caused by the control connection close for a long time not receiving commands. Could you please share your code or tell me what's the scenario of your usage.

I am working to find a solution for this issue.

Best regards.

I do not think this is a timeout issue, as the entire process takes less than 20 minutes and processes a couple hundred records, so that average time between FTP calls would be less than 10 seconds.

Here is the outline of what I am doing.

*******************************************************************

For Each file In fileList
'Do some non-ftp processing
'Call sub procedure to lookup filesize
Next

'When all processing is done, dump the results into Excel using Aspose.Cells.

*******************************************************************

So as you can see, it is a very basic process with very little time betwen FTP calls.

Our FTP host asked about the commands we were using, and so I assumed that the following pairings were correct. Please let me know if I am mistaken.

Your GetFileSize method uses the base 'SIZE [filename]' ftp command.

Your ListDirectoryDetails method uses the base 'LIST' ftp command.

They also asked for a log of the transactions, but I didn't see that Aspose.Network.Ftp has any logging capabilities. Is this something that could be added, or did I overlook something?

Thanks!

Dan

Do you have any update on this issue?

Thanks!

Dan