title: FTP:Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host
body: <p>I'm newbie to FTP.I am trying to write to a file in FTP using StreamWriter.Once after writing to the file,i dont want to close the stream as i have some work which has to be done.Later after some 1 hour,if i try to write using the same streamWriter i get the above error.
  Below is my code snippet</p>
  
  <pre><code>public void WriteToFTP()
      {
          bool isConnectionEstablished = false;
          StreamWriter stream = null;
          try
          {
              for (int i = 1; i &lt; 5; i++)
              {
                  string message = string.Format("File - {0}.", i.ToString());
                  if (!isConnectionEstablished)
                  {
                      FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri("My FTP path"));
                      request.Credentials = new NetworkCredential("asdf", "asdf@123");
                      request.Proxy = null;
                      request.UseBinary = true;
                      request.ConnectionGroupName = string.Empty;
                      request.UsePassive = true;
                      request.EnableSsl = false;
                      isConnectionEstablished = true;
                      stream = new StreamWriter(request.GetRequestStream()) { AutoFlush = true };
                  }
                  stream.WriteLine(message);//Here i am getting the error for the i = 2(after doing my work)
                  //Doing work which may take more than 1 hour.
              }
          }
          catch (Exception exe)
          {
              //The Error "Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host" is being caught here.
          }
          finally
          {
              if (stream != null)
                  stream.Close();
          }
      }
  </code></pre>