【发布时间】:2014-07-06 03:21:57
【问题描述】:
所以我正在尝试将文件上传到我的 ftp,但我希望它测试 FTP 详细信息是否正确。我在下面找到了这段代码,虽然它在连接时显示“存在”但当它无法连接时 [with fake details] 它什么也没做(我想要一个错误来显示它无法连接)
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
我该如何解决这个问题?
【问题讨论】: