title: Visual Basic: FTP Download
body: <p>I have tried different codes and non of them works for downloading a file from example DriveHQ.</p>
  
  <p>But i do manage to upload so the Host seems to be fine.</p>
  
  <p>EDIT*</p>
  
  <pre><code>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/" &amp; "" &amp; 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 &lt;&gt; 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
  </code></pre>
  
  <p>//Simon</p>