Discuss (FTP), (FTP on .NET CF) and (FTPS, SFTP and SCP).
no avatar
User

rimmeraj

Posts

2

Joined

Tue Feb 23, 2010 10:12 am

Connection not closed due to timeout / no reply.

by rimmeraj » Tue Feb 23, 2010 10:23 am

Hi,

I am using edtFTPNet/Free and it has been a very reliable solution.

But I am hitting a particular issue where connections to the FTP server are not being closed.
This is an issue because the FTP server restricts the number of connections from a given IP.

so, the snippet of code is below. The code is called repeatedly and reuses the connection between calls.
This works great 99% of the time, but every so often a timeout occurs on the 'Put'.
I have exception handling that catches this occurance, and it tries to reconnect to the server.
BUT, I cannot 'close' the old connection at this point. Once the exception happens on the Put it is not accesible (isConnected = False).
if 8 of these occur in 15 minutes I suddenly cannot FTP to the server at all.

Is there some way I should be closing the connection (other than using connection.quit)?

Thanks

If connection Is Nothing Then
connection = New FTPClient(SendFtpFile.SendFTP.host)
connection.StrictReturnCodes = False
connection.Login(SendFtpFile.SendFTP.username, SendFtpFile.SendFTP.password)
' log.Debug("Setting up passive, ASCII transfers")
connection.ConnectMode = FTPConnectMode.PASV
End If

If Not connection.IsConnected Then
connection.Connect()
connection.Login(SendFtpFile.SendFTP.username, SendFtpFile.SendFTP.password)
connection.ConnectMode = FTPConnectMode.PASV
End If

If SendFtpFile.binary Then
connection.TransferType = FTPTransferType.BINARY
Else
connection.TransferType = FTPTransferType.ASCII
End If

'set timeout
connection.Timeout = SendFtpFile.timeout

'put file.
connection.Put(SendFtpFile.sourceFile, SendFtpFile.desinationdirectory & "/" & SendFtpFile.filename)
no avatar
User

support2

Posts

3987

Joined

Tue May 18, 2004 8:30 am

Re: Connection not closed due to timeout / no reply.

by support2 » Tue Feb 23, 2010 10:42 am

Call QuitImmediately() in the exception handler before reconnecting.
no avatar
User

rimmeraj

Posts

2

Joined

Tue Feb 23, 2010 10:12 am

Re: Connection not closed due to timeout / no reply.

by rimmeraj » Wed Feb 24, 2010 8:52 am


Who is online

Users browsing this forum: No registered users and 13 guests

Powered by phpBB ® | phpBB3 Style by KomiDesign