title: Uploading a file via FtpWebRequest The remote server returned an error 227 entering passive mode
body: <p>I'm reading data from my database and reformatting it into a comma delimited CSV file which I need to upload to an FTP server.</p>
  
  <p>This procedure reads in the Byte array of the string that contains the data in the comma delimited format and uploads it to the server:</p>
  
  <pre><code>Private Sub uploadToServer(ByVal data() As Byte, ByVal filename As String)
      Try
          Dim ftpr As FtpWebRequest = _
              DirectCast(WebRequest.Create(String.Format("ftp://ftp.this.com/{0}", filename)), FtpWebRequest)
          ftpr.Credentials = New NetworkCredential("thisUser", "somePassword0rOther")
          ftpr.Method = WebRequestMethods.Ftp.UploadFile
  
          Using stream As Stream = ftpr.GetRequestStream()
              stream.Write(data, 0, data.Length)
          End Using
      Catch ex As Exception
          el.WriteEntry(String.Format("Error uploading file: {1}", vbNewLine &amp; ex.Message))
      End Try
  End Sub
  </code></pre>
  
  <p>At least, that's what it's supposed to do... and what it did yesterday. Now though, I keep getting this returned in the Exception:</p>
  
  <blockquote>
    <p>The remote server returned an error: 227 Entering Passive Mode</p>
  </blockquote>
  
  <p>I've been getting the same error while attempting to connect to the same server with FileZilla which makes me think that the problem is on the server.</p>
  
  <p>I don't intend to troubleshoot server issues here, but what I do need is confirmation that there's nothing wrong with this code. Then I can go to serverfault and query about any possible server issues there.</p>
  
  <p>So... Is there anything wrong with this code?</p>
  
  <p><strong>EDIT</strong><br>
  Testing other ways of accessing the FTP I've discovered:</p>
  
  <ul>
  <li>Accessing the FTP via RDP into the server itself (Windows Server 2008 R2) works</li>
  <li><p>FileZilla returns <code>Connection timed out. Failed to retrieve directory listing</code></p></li>
  <li><p>Connecting via Windows Explorer returns <code>An error occurred opening that folder on the FTP Server. Make sure you have permission to access that folder. Details: The operation timed out</code>. The same happens when anyone in the office makes an attempt to access the server via FTP.</p></li>
  </ul>
  
  <p>I'm pretty sure this is also what's happening in my application.</p>