谁有vb.net测试ftp服务器上文件是否存在的代码3
发布网友
发布时间:2023-11-16 12:41
我来回答
共1个回答
热心网友
时间:2024-10-23 22:42
Dim ftpclient As System.Net.FtpWebRequest = System.Net.FtpWebRequest.Create(New System.Uri("ftp://183.136.203.146/软件"))
ftpclient.UseBinary = True
ftpclient.Credentials = New System.Net.NetworkCredential("upload", "upload")
ftpclient.Method = System.Net.WebRequestMethods.Ftp.ListDirectoryDetails
ftpclient.KeepAlive = False
Dim ftpresponse As System.Net.FtpWebResponse = CType(ftpclient.GetResponse, System.Net.FtpWebResponse)
Console.WriteLine(ftpresponse.StatusCode.ToString + " " + ftpresponse.StatusDescription)
Dim content(1024) As Byte
Dim index_a As Integer = 0
index_a = ftpresponse.GetResponseStream.Read(content, 0, content.Length)
Dim contentstring As String = String.Empty
While index_a > 0
index_a = ftpresponse.GetResponseStream.Read(content, 0, content.Length)
contentstring += System.Text.Encoding.UTF8.GetString(content)
End While
ftpresponse.Close()
If contentstring.LastIndexOf("aaa.txt") > 0 Then
MsgBox("存在")
Else
MsgBox("不存在")
End If