title: Indy error 10038 "Socket operation on non-socket" after 61 seconds of inactivity
body: <p>I want to download some large files (GB) from an FTP server. 
  The download of the first file always works. Then when trying to get the second file I get: </p>
  
  <blockquote>
    <p>"Socket Error # 10038. Socket operation on non-socket."</p>
  </blockquote>
  
  <p>The error is on 'Get'. After 'Get' I see these messages (via FTP status event):</p>
  
  <pre><code>   Starting FTP transfer
     Disconnecting.
     Disconnected.
  </code></pre>
  
  <p>The code is like this:</p>
  
  <pre><code>{pseudo-code}
  for 1 to AllFiles do 
   begin 
     if Connect2FTP then 
      begin
       FTP.Get(Name, GzFile, TRUE, FALSE);  &lt;--- Socket operation on non-socket" error (I also get EIdConnClosedGracefully 'Connection Closed Gracefully' in IDE, F9 will resume execution without problems, but this is OK)
       Unpack(GzFile); &lt;--- this takes more than 60 seconds
      end;
   end;
  if FTP.Connected
  then FTP.Disconnect;
  </code></pre>
  
  <p>--</p>
  
  <pre><code>function Connect2FTP(FTP: TIdFTP; RemoteFolder: string; Log: TRichLog): Boolean;      
  begin
   Result:= FTP.Connected;
   if NOT Result then
    begin         { We are already connected }
     FTP.Host    := MyFTP;
     FTP.Username:= usr;
     FTP.Password:= psw;
  
     TRY
      FTP.Connect;
     EXCEPT
      on E: Exception DO
  
     Result:= FTP.Connected;
     if Result then FTP.ChangeDir(RemoteFolder); 
    end;
  end;
  </code></pre>
  
  <p><em>Full code here: <a href="http://pastebin.com/RScj86R8" rel="nofollow noreferrer">http://pastebin.com/RScj86R8</a> (PAS) or here <a href="https://ufile.io/26b54" rel="nofollow noreferrer">https://ufile.io/26b54</a> (ZIP)</em></p>
  
  <p>I think the problem appears after calling 'Unpack' which takes few minutes.  </p>
  
  <p><strong>UPDATE: CONFIRMED:</strong> The problem appears after calling 'Unpack'. I removed the call and everything is fine. Pausing (sleep or break point) the program between downloads for a while (I think for more than 60 sec) will create the same problem.</p>
  
  <p><a href="https://i.stack.imgur.com/PTgv8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PTgv8.png" alt="enter image description here"></a></p>