title: Uploading a file to a ftp server fails
body: <p>I have a small C# winform in which I generate some text files and then move them to an ftp server.
  When I try to move them to the production server it fails under </p>
  
  <blockquote>
    <p>The remote server returned an error: (530) Not logged in.</p>
  </blockquote>
  
  <p>If I log in to the ftp via cmd/ftp with the same ftp address, username and password, everything is ok. I also installed a local ftp server on my machine and tested it to see if perhaps my code is generating the error, but locally it works like a charm, I have the problem only with the production ftp server. 
  Below is my code to connect and upload the files to the ftp server:</p>
  
  <pre><code>string[] FileName = Directory.GetFiles(outputpath);
  
  foreach (string txtFile in FileName)
  {
       FileInfo toUpload = new FileInfo(txtFile);
  
       FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://" + tbFTPAddress.Text + @"//" + toUpload.Name);
  
       request.Credentials = new NetworkCredential(tbFTPUserName.Text.Trim(), tbFTPPassword.Text.Trim());
  
       request.Method = WebRequestMethods.Ftp.UploadFile;
  
       Stream ftpStream = request.GetRequestStream();
       FileStream file = File.OpenRead(txtFile);
  
       int length = 1024;
       byte[] buffer = new byte[length];
       int bytesRead = 0;
  
       try
       {
           do
           {
               bytesRead = file.Read(buffer, 0, length);
               ftpStream.Write(buffer, 0, bytesRead);
           }
           while (bytesRead != 0);
  
           file.Close();
           ftpStream.Close();
       }
       catch (Exception ex)
       {
           MessageBox.Show(ex.Message, "Error encountered!", MessageBoxButtons.OK, MessageBoxIcon.Error);
       }
       finally
       {
           if (file != null) file.Close();
           if (ftpStream != null) ftpStream.Close();
       }
  }
  </code></pre>
  
  <p>The error comes at: <code>Stream ftpStream = request.GetRequestStream();</code></p>
  
  <p>Any ideas?</p>
  
  <p>Thanks!</p>