title: FTPWebRequest: Transfer from one FTP to another FTP, Destination file corrupt
body: <p>Here's my agonizing problem. I'm transferring from one FTP (a Dev site) to another FTP (a Test site). Spare me the thoughts of changing this process. It's out of my hands. In any case, here's my method:</p>
  
  <pre><code>Public Function TransferFile(originalFile As String, destinationFile As String) As String
          Try
              'FileStream for holding the file
              Dim uploadRequest As FtpWebRequest = WebRequest.Create(destinationFile)
              uploadRequest.Method = WebRequestMethods.Ftp.UploadFile
              uploadRequest.Credentials = New NetworkCredential(ftp_user, ftp_pw)
              uploadRequest.UseBinary = True
              uploadRequest.UsePassive = False
  
              'connect to the server
              Dim fileRequest As FtpWebRequest = WebRequest.Create(originalFile)
              fileRequest.Method = WebRequestMethods.Ftp.DownloadFile
              fileRequest.Credentials = New NetworkCredential(ftp_user, ftp_pw)
              fileRequest.UseBinary = True
              fileRequest.UsePassive = False
  
              'get the servers response
              Dim response As WebResponse = fileRequest.GetResponse()
  
              'retrieve the response stream
              Dim stream As Stream = response.GetResponseStream()
              CopyStream(stream, uploadRequest.GetRequestStream)
  
              stream.Close()
              response.Close()
  
              Return "File transfered"
          Catch ex As System.Security.SecurityException
              Return ex.Message
          Catch ex As Exception
              Return ex.Message
          End Try
      End Function
  
      Public Shared Sub CopyStream(input As Stream, output As Stream)
        Dim buffer As Byte() = New Byte(32767) {}
         While True
          Dim read As Integer = input.Read(buffer, 0, buffer.Length)
          If read &lt;= 0 Then
              Return
          End If
          output.Write(buffer, 0, read)
         End While
      End Sub
  </code></pre>
  
  <p>This works perfectly for ASPX files and their .vb code behinds. When we try to transfer .DLL files, they show up on the server as 0 bytes, and sometimes actually transfer. The problem is that, despite being the same size as the original, they act as if they are corrupt. Does anyone have a solution?</p>