title: How to handle a moody ftp server?
body: <p>I want to upload data to an ftp server using a small application. I use this function:</p>
  
  <pre><code>public void upload(string remoteFile, string localFile)
  {
      try
      {
         ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + remoteFile);
          ftpRequest.Credentials = new NetworkCredential(user, pass);
  
          ftpRequest.UseBinary = true;
          ftpRequest.UsePassive = true;
          ftpRequest.KeepAlive = true;
  
          ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
  
          ftpStream = ftpRequest.GetRequestStream();
  
          FileStream localFileStream = new FileStream(localFile, FileMode.Open);
  
          byte[] byteBuffer = new byte[bufferSize];
          int bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
  
          try
          {
              while (bytesSent != 0)
              {
                  ftpStream.Write(byteBuffer, 0, bytesSent);
                  bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
              }
          }
          catch (Exception ex) { Console.WriteLine(ex.ToString()); }
  
          localFileStream.Close();
          ftpStream.Close();
          ftpRequest = null;
      }
      catch (Exception ex) { Console.WriteLine(ex.ToString()); }
      return;
  }
  </code></pre>
  
  <p>The Server however does not respond to my STOR request, or any other request in regard to the files on the server (LIST, etc.):
  <a href="https://i.stack.imgur.com/XtMYf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XtMYf.png" alt="enter image description here"></a></p>
  
  <p>However, a programm like FileZilla can connect to the server and get a proper response.
  <a href="https://i.stack.imgur.com/CjEJZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CjEJZ.png" alt="enter image description here"></a></p>
  
  <p>Once FileZilla established a connection to the server, my application also can communicate with the server and upload files.</p>
  
  <p>What is happening here? How can I handle this?</p>