title: The remote server returned an error: (421) Service not available, closing control connection
body: <p>I am running this code for alot of files to transfer locally to another server via ftp. The problem is I am periodically getting the error The remote server returned an error: (421) Service not available, closing control connection. Is there a problem with the code, a better way to transfer the files that is quicker more efficient. All the files need to be transfered so I was thinking a while loop and catching the error until all files in the folder have transfered. It is a periodic error I am getting:</p>
  
  <pre><code>foreach (FileInfo file in files)
  {
      try
      {
          // Get the object used to communicate with the server.
          FtpWebRequest request =
              (FtpWebRequest)
                  WebRequest.Create(String.Format("{0}{1}/{2}", Host, destinationPath,
                      file.Name));
          request.Method = WebRequestMethods.Ftp.UploadFile;
          request.KeepAlive = false;
          /* 20 mins timeout */
          request.Timeout = 1200000;
          request.ReadWriteTimeout = 1200000;
  
          // This example assumes the FTP site uses anonymous logon.
          request.Credentials = new NetworkCredential(Username, Password);
  
          // Copy the contents of the file to the request stream.
          byte[] fileContents = File.ReadAllBytes(file.FullName);
  
          request.ContentLength = fileContents.Length;
  
          using (Stream requestStream = request.GetRequestStream())
          {
              requestStream.Write(fileContents, 0, fileContents.Length);
          }
  
          //using (FtpWebResponse response = (FtpWebResponse) request.GetResponse())
          //{
  
          //}
  
          if (deleteSourcePath)
          {
              File.Delete(file.FullName);
          }
      }
      catch (Exception ex)
      {
          //  Log.Warn("Error Moving Images", ex.Message);
      }
  }
  </code></pre>