VB .NET检查FTP帐户是否已经存在

时间:2018-08-10 00:08:38

标签: vb.net ftp

我尝试为Windows OS创建一个应用程序,以便可以使用FTP帐户同步计算机中的文件。

我需要Visual Basic中的一个函数来检查FTP帐户是否存在。

例如:

Public Function CheckAccountFTP(ByVal host As String, ByVal user As String, ByVal pass As String) As Boolean
    '' Function Content ...
    ... Try/Catch with what ...
End Function

我可以用来做什么?

1 个答案:

答案 0 :(得分:0)

我想我可以使用此功能:

Public Function CheckAccountFTP(ByVal sHost As String, ByVal sUser As String, ByVal sPassword As String) As Boolean
    Dim bStatus As Boolean
    Dim request = DirectCast(WebRequest.Create(sHost), FtpWebRequest)
    request.Method = WebRequestMethods.Ftp.ListDirectory
    request.Credentials = New NetworkCredential(sUser, sPassword)
    Try
        Using request.GetResponse()
            bStatus = True
        End Using
    Catch
        bStatus = False
    End Try
    Return bStatus
End Function

然后将使用它:

    If CheckAccountFTP("ftp://localhost", "aninu", "123123123") = True Then
        '' OK ...
    Else
        '' Not OK ...
    End If