我已經嘗試過不同的代碼,並且它們都不適用於從示例DriveHQ下載文件。Visual Basic:FTP下載
但我設法上傳,所以主機似乎很好。
編輯*
sub()
GetFile("downloadme.txt", "DESKTOP")
End Sub
Public Function GetFile(ByVal Name As String, ByVal DestFile As String) As Boolean
Dim oFTP As FtpWebRequest = CType(FtpWebRequest.Create("ftp://ftp.drivehq.com/" & "" & Name), FtpWebRequest)
oFTP.Credentials = New NetworkCredential("user", "passw")
oFTP.Method = WebRequestMethods.Ftp.DownloadFile
oFTP.KeepAlive = KeepAlive
' oFTP.EnableSsl = UseSSL
' If UseSSL Then ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate)
oFTP.UseBinary = True
Dim response As FtpWebResponse = CType(oFTP.GetResponse, FtpWebResponse)
Dim responseStream As Stream = response.GetResponseStream
Dim fs As New FileStream(DestFile, FileMode.Create)
Dim buffer(2047) As Byte
Dim read As Integer = 1
While read <> 0
read = responseStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, read)
End While
responseStream.Close()
fs.Flush()
fs.Close()
responseStream.Close()
response.Close()
oFTP = Nothing
Return True
End Function
Public Function ValidateServerCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
If sslPolicyErrors = sslPolicyErrors.RemoteCertificateChainErrors Then
Return False
ElseIf sslPolicyErrors = sslPolicyErrors.RemoteCertificateNameMismatch Then
Dim z As System.Security.Policy.Zone = System.Security.Policy.Zone.CreateFromUrl(CType(sender, HttpWebRequest).RequestUri.ToString)
If z.SecurityZone = System.Security.SecurityZone.Intranet Or z.SecurityZone = System.Security.SecurityZone.MyComputer Then
Return True
End If
Return False
End If
Return True
End Function
//西蒙
你可以發佈一些你已經試過的代碼,所以我們可以引導你在正確的方向嗎? – 2011-03-15 21:24:26
在這裏你去! – user564612 2011-03-15 21:35:25
@carmstrong告訴我,如果你得到它的權利 – user564612 2011-03-15 21:37:22