0
所以我想上传文件到我的FTP,虽然我想要它来测试FTP的细节是否正确。我发现下面的代码,虽然它的工作原理虽然它显示'存在'当它连接,但是当它无法连接[与假的细节]它不会做任何事情(我想要一个错误显示说它不能连接)VB.NET测试FTP连接
Imports System.Net
Dim request = _
DirectCast(WebRequest.Create _
("ftp://ftp.example.com/folder_here/"), FtpWebRequest)
request.Credentials = _
New NetworkCredential("user_here", "pass_here")
request.Method = WebRequestMethods.Ftp.ListDirectory
Try
Using response As FtpWebResponse = _
DirectCast(request.GetResponse(), FtpWebResponse)
' Folder exists here
MsgBox("exists!")
End Using
Catch ex As WebException
Dim response As FtpWebResponse = _
DirectCast(ex.Response, FtpWebResponse)
'Does not exist
If response.StatusCode = _
FtpStatusCode.ActionNotTakenFileUnavailable Then
MsgBox("Doesn't exist!")
End If
End Try
我该如何解决这个问题?