Check FTP connection state

+1 vote
asked Jan 26, 2010 by Martin House (570 points)
edited Feb 9, 2010

Hi I'm using Rebex.Net.Ftp 2.0.2567, and I want to check the Ftp connection state at the end of my try/catch block in order to disconnect if there was some error during transfer etc. I thought something like this might work :

Finally

    If ftp.GetConnectionState.Connected Then
        UpdateStatus("Disconnecting")
        ftp.Disconnect()
    End If

End Try

However, I get a InvalidOperationException error telling me that I'm "Not connected to the server".

Can anyone suggest where I'm going wrong please ?

Thanks, Martin

Applies to: Rebex FTP/SSL

1 Answer

+1 vote
answered Jan 26, 2010 by Lukas Pokorny (94,350 points)
edited Jan 26, 2010

This is caused by a bug in the Ftp object's GetConnectionState method that was fixed in Rebex FTP 2.3.2666: GetConnectionState no longer fails on disconnected objects. Sorry for inconvenience!

Workaround for 2.0.2567:

   Finally

       If ftp.State <> FtpState.Disconnected _
          AndAlso ftp.GetConnectionState.Connected Then
            UpdateStatus("Disconnecting")
            ftp.Disconnect()
       End If

   End Try
commented Jan 26, 2010 by Martin House (570 points)
Thanks ! I'll try the workaround
...