title: FTP error 227 entering passive mode
body: <p>i'm trying to upload file to ftp server. tried some code samples, but alway getting this error, entering passive mode. for example, i can create a directory with this code</p>
  
  <pre><code>FtpWebRequest reqFTP;
  try
  {
      // dirName = name of the directory to create.
      reqFTP = (FtpWebRequest)FtpWebRequest.Create(
               new Uri("ftp://" + ftpServerIP + "/" + dirName));
      reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;
      reqFTP.UseBinary = true;
      reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
      reqFTP.UsePassive = false;
      FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
      Stream ftpStream = response.GetResponseStream();
  
      ftpStream.Close();
      response.Close();
  }
  catch (Exception ex)
  {
      MessageBox.Show(ex.Message);
  }
  </code></pre>
  
  <p>or for example i can rename a file. but cannot upload file with this code</p>
  
  <pre><code>string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;
  FtpWebRequest reqFTP;
  reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(
           "ftp://" + ftpServerIP + "/" + fileInf.Name));
  reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
  reqFTP.KeepAlive = false;
  reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
  reqFTP.UseBinary = true;
  reqFTP.ContentLength = fileInf.Length;
  
  int buffLength = 2048;
  byte[] buff = new byte[buffLength];
  int contentLen;
  
  FileStream fs = fileInf.OpenRead();
  
  try
  {
      Stream strm = reqFTP.GetRequestStream();
      contentLen = fs.Read(buff, 0, buffLength);
      while (contentLen != 0)
      {
          strm.Write(buff, 0, contentLen);
          contentLen = fs.Read(buff, 0, buffLength);
      }
      strm.Close();
      fs.Close();
  }
  catch(Exception ex)
  {
      MessageBox.Show(ex.Message, "Upload Error");
  }
  </code></pre>
  
  <p>getting exception at <code>reqFTP.GetRequestStream()</code>. </p>
  
  <p>If I use <code>reqFTP.UsePassive=false</code> then i get “</p>
  
  <blockquote>
    <p>The remote server returned an error: (500) Syntax error, command unrecognized”. </p>
  </blockquote>
  
  <p>What should i do?</p>