2011-03-15 7 views
0

다른 코드를 시도했지만 그 중 일부는 예제 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 

// 사이먼

+2

시도한 코드를 게시하여 올바른 방향으로 안내 할 수 있습니까? –

+0

여기 있네 !!!! – user564612

+0

@carmstrong 당신이 그것을 올바르게 얻는다면 말해주세요. – user564612

답변

0

는 오류 메시지를 받고, 아니면 단지 당신이 할 기대하지 않는 * EDIT? FileStream을 만들고이를 DESKTOP이라는 파일로 지정하면 실제로 의도했던 것입니까 아니면이 예입니까?

+0

런타임 오류가 발생합니다. 오류 530 : 로그인하지 않았지만 다음과 같습니다 :( – user564612

+0

코드가 유효합니다. 올바른 사용자 이름과 암호로 FTP 서버에서 테스트했습니다. (530) 로그인되지 않았습니다. 잘못된 사용자 이름/암호를 의미합니다. –

+0

@Chris 내가 올바른 사용자 이름과 암호를 가지고 있는지 확인하려면 웹 사이트 – user564612