title: Unable to read data from the transport connection. FtpWebRequest. C#
body: <p>I'm configuring a service to read some csv files from a ftp repository. When I debug in my local machine it works perfectly but when I build it and make it run, It doesn't work. I put some console logs to write the steps the program takes. I could see it connects to the ftp and reads its files but not the whole content of it. Example: the first file has 170000 lines, the program will read only the first 489 ones and then the message: &quot;Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host&quot; comes to me. It runs by itself three more times, and I know it because the same message comes 4 times but no record is commited. Below there is part of the code.</p>
  <pre><code>    public async Task&lt;IResult&gt; GravaSore(List&lt;string&gt; arquivos) //caller
      {
              foreach (var item in arquivos)
              {
                  await ProcessaGravacao(item);
              }
              return new TypeResult&lt;bool&gt;(&quot;processados&quot;); ;
      }
  
  
  
      private async Task&lt;IResult&gt; ProcessaGravacao(string item) //called
      {
          var urlFtp = [ftp_string];
  
          FtpWebRequest request = (FtpWebRequest)WebRequest.Create(urlFtp);
          ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
          request.Credentials = new NetworkCredential(&quot;usr&quot;, &quot;pwd&quot;);
          request.Method = WebRequestMethods.Ftp.DownloadFile;
          request.EnableSsl = true;
          request.UsePassive = true;
  
          FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  
          Stream responseStream = response.GetResponseStream();
          StreamReader reader = new StreamReader(responseStream);
          String linha;
  
          try
          {
              var contador = 0;
              while ((linha = reader.ReadLine()) != null)
              {
                  if (!linha.Contains(&quot;cpf&quot;))
                  {
                      var colunas = linha.Split(&quot;;&quot;);
                      var cpf = colunas[0];
                      var core = colunas[1].Substring(0, 5);
                      var core2 = decimal.Parse(core);
                      var data = colunas[2].Split(&quot;-&quot;);
                      var ano = int.Parse(data[0]);
                      var mes = int.Parse(data[1]);
                      var dataCore = new DateTime(ano, mes, 01, 01, 01, 01);
                      var pessoa = _pRepositorio.OPPCpf(cpf);
                      if (pessoa == null)
                          break;
                      var cliente = pessoa.Cliente;
  
                      Csore entity = new Csore { DataHora = dataCore, Cliente = cliente, Core = core2 };
                      await _Repositorio.AddAsync(entity);
  
                      contador++;
                      if (contador &gt;= 5000)
                      {
                          contador = 0;
                          await _Repositorio.CommitAsync();
                      }
                  }
              }
              if(contador &gt; 0)
                  await _Repositorio.CommitAsync();
              Console.WriteLine(&quot;sucesso&quot;);
  
              reader.Close();
              response.Close();
              return new TypeResult&lt;bool&gt;(&quot;Sucesso&quot;);
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.Message);
              return null;
          }
      }
  </code></pre>