title: After enabling security in FTP session, getting 500 Syntax error, command unrecognized
body: <p>I am using this code to connect my server and downloading the files. It is working fine.</p>
  
  <pre><code>public void downloadFile(object args)
  {
      writeStream = null;
      response = null;
      reader = null;
      int dataLength = 0;
  
      try
      {
          Array argArray = new object[3];
          argArray = (Array)args;
          ProgressBar progressBar1 = (ProgressBar)argArray.GetValue(0);
          Label lbProgress = (Label)argArray.GetValue(1);
  
          FTPInfo ftpInfo = (FTPInfo)argArray.GetValue(2);
          string ipAddress = ftpInfo.IpAddress;
  
          string path = ftpInfo.Path;
          string fileName = ftpInfo.FileName;
  
          path = Regex.Replace(path, "_.", "_e");
          fileName = Regex.Replace(fileName, "_.", "_e");
  
          string uri = null;
          if (path.Equals(""))
          {
              uri = ipAddress + fileName;
          }
          else
          {
              uri = ipAddress + path + "/" + fileName;
          }
          string[] temp = ipAddress.Split('/');
          string ip = "mchmultimedia.com";
          string userName = ftpInfo.UserName;
          string password = ftpInfo.Password;
          downloadedData = new byte[0];
          ftp = new FTPClass(path);
          ftp.FtpServer = ip;
          ftp.FtpUsername = userName;
          ftp.FtpPassword = password;
          ftp.FtpLogin();
          dataLength = (int)ftp.GetFileSize(fileName);
          Logger.LogDebugMessage("DataLength :" + dataLength.ToString());
          ftp.CloseConnection();
          FtpWebRequest request = FtpWebRequest.Create(uri) as FtpWebRequest;
          request.Method = WebRequestMethods.Ftp.DownloadFile;
          request.Credentials = new NetworkCredential(userName, password);
          request.UsePassive = true;
          request.UseBinary = true;
          request.KeepAlive = false;
  
          //Set up progress bar
          UpdateProgressBarValue(progressBar1, 0);
          SetProgressBarMaxValue(progressBar1, dataLength);
  
          response = request.GetResponse() as FtpWebResponse;
          reader = response.GetResponseStream();
  
          if (!Directory.Exists(GlobalClass.ZIPPED_FOLDER))
              Directory.CreateDirectory(GlobalClass.ZIPPED_FOLDER);
          writeStream = new FileStream(GlobalClass.ZIPPED_FOLDER + "\\" + fileName, FileMode.Create);
          int Length = 2048;
          Byte[] buffer = new Byte[Length];
          int bytesRead = 0;
          Logger.LogDebugMessage("Before while :" + dataLength.ToString());
          while (true)
          {
              Application.DoEvents(); 
  
              bytesRead = reader.Read(buffer, 0, buffer.Length);
              if (bytesRead == 0)
              {
                  try
                  {
                      try
                      {
                          reader.Close();
                      }
                      catch (Exception ex)
                      {
                          Logger.LogErrorMessage("reader close if bytesRead ==00", ex);
  
                      }
  
                      try
                      {
                          response.Close();
                      }
                      catch (Exception ex)
                      {
                          Logger.LogErrorMessage("response close if  bytesRead ==00", ex);
                      }
  
                      try
                      {
                          writeStream.Close();
                      }
                      catch (Exception ex)
                      {
                          Logger.LogErrorMessage("writeStream close if  bytesRead ==00", ex);
                      }
  
                  }
                  catch (Exception ex)
                  {
  
                  }
                  UpdateProgressBarValue(progressBar1, progressBar1.Maximum);
                  Application.DoEvents();
                  break;
              }
              else
              {
                  writeStream.Write(buffer, 0, bytesRead);
  
                  if (progressBar1.Value + bytesRead &lt;= progressBar1.Maximum)
                  {
                      totalBytesRead = progressBar1.Value + bytesRead;
                      int percentage = (int)((double)totalBytesRead / dataLength * 100);
                      UpdateProgressBarValue(progressBar1, totalBytesRead);
  
                      SetText(lbProgress, "File download " + percentage.ToString() + " % completed");
                      if (percentage == 100)
                      {
                          if (totalBytesRead == dataLength)
                          {
                              try
                              {
                                  try
                                  {
                                      reader.Close();
                                  }
                                  catch (Exception ex)
                                  {
                                      Logger.LogErrorMessage("reader close if percentage==100", ex);
                                  }
  
                                  try
                                  {
                                      response.Close();
                                  }
                                  catch (Exception ex)
                                  {
                                      Logger.LogErrorMessage("response close if percentage==100", ex);
                                  }
  
                                  try
                                  {
                                      writeStream.Close();
                                  }
                                  catch (Exception ex)
                                  {
                                      Logger.LogErrorMessage("writeStream close if percentage==100", ex);
                                  }
  
                              }
                              catch (Exception ex)
                              {
  
                              }
                              SetText(lbProgress, "File download successfully completed,Please wait...");
                              unzipFile(fileName);
                          }
  
                      }
  
                      RefreshProgressBar(progressBar1);
                      Application.DoEvents();
                  }
  
              }
          }
      }
      catch (System.Threading.ThreadAbortException ex)
      {
          if (thread != null)
          {
              thread.Abort();
          }
          Logger.LogErrorMessage("ThreadAbortException", ex);
  
      }
      catch (Exception ex)
      {
          Logger.LogErrorMessage("Exception there was an error connecting", ex);
          Logger.ReportBug("There was an error connecting to the FTP Server.", ex);
      }
      finally
      {
          try
          {
              try
              {
                  reader.Close();
              }
              catch (Exception ex)
              {
                  Logger.LogErrorMessage("read finally", ex);
              }
  
              try
              {
                  response.Close();
              }
              catch (Exception ex)
              {
                  Logger.LogErrorMessage("resonse finally", ex);
              }
  
              try
              {
                  writeStream.Close();
              }
              catch (Exception ex)
              {
                  Logger.LogErrorMessage("writeStream finally", ex);
              }
          }
          catch (Exception ex)
          {
  
          }
      }
  }
  </code></pre>
  
  <p>But client needs it to be secure FTP. So I tried by setting </p>
  
  <pre><code>request.EnableSsl = true;
  </code></pre>
  
  <p>as specified in <a href="https://stackoverflow.com/questions/440463/differences-between-sftp-and-ftp-over-ssh">Differences between SFTP and &quot;FTP over SSH&quot;</a></p>
  
  <p>And it throws:</p>
  
  <blockquote>
    <p>The remote server returned an error: (500) Syntax error, command unrecognized. </p>
  </blockquote>