Check Connection to the FTP Server

Jul 31, 2008 at 4:21 PM
Edited Jul 31, 2008 at 4:36 PM
I have found it useful to check if the credentials will allow you to logon before attempting any action on the server. Here is the additional method which may be usefully included in a later release.... 

Public Function CheckLogon() As Boolean

Dim ftp As Net.FtpWebRequest = GetRequest(Hostname)
ftp.Method = Net.WebRequestMethods.Ftp.PrintWorkingDirectory

Try
    'get response but ignore it
    Dim str As String = GetStringResponse(ftp)
Catch ex As WebException
    If ex.Status = WebExceptionStatus.Success Then
        Return True
    Else
        Return False
    End If
Catch ex As Exception
    Throw
End Try

E
nd Function

 

 

 

 

 

 

 

 

 

 

Aug 1, 2008 at 12:24 PM
Good suggestion CodeSurfer.