title: ftplib is timing out
body: <p>I'am attempting to send 5 files over to an ftp server. However, only the first 3 out of the 5 files are sent, while the last 2 are not sent.</p>
  <p>I suspect it has to do with timing out but im not sure, as it takes around 5 minutes for the first 3 files to be transferred.</p>
  <p>Any suggestions?</p>
  <p>##OLD CODE</p>
  <pre><code>import subprocess
  
  #ftp credentials
  server='myserver.host.com'
  user='admin@mywebsite.com'
  password='mypassword'
  
  #logging in to ftp
  proc =subprocess.Popen(['ftp -p {}'.format(server)],shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
  #sending username
  proc.stdin.write(bytes(user+'\n',encoding='UTF-8'))
  proc.stdin.flush()
  #sending password
  proc.stdin.write(bytes(password+'\n',encoding='UTF-8'))
  proc.stdin.flush()
  
  #name of ftp directory were files will be transferred
  ftpdirectory='ftpdir'
  
  #list of file directories to be transferred 
  filestotransfer=['/home/user/Desktop/file1.csv','/home/user/Desktop/file2.csv','/home/user/Desktop/file3.csv','/home/user/Desktop/file4.csv','/home/user/Desktop/file5.csv']
  
  #transferring files one by one
  for i in filestotransfer:
      filename=i.split('/')[-1]
      syntaxx='put &quot;{}&quot; &quot;/{}/{}&quot;'.format(i,ftpdirectory,filename) #put /home/user/Desktop/file1.csv /ftpdir/file1.csv
      proc.stdin.write(bytes(syntaxx + '\n', encoding='UTF-8'))
      proc.stdin.flush()
  </code></pre>
  <p>##SOLUTION</p>
  <pre><code>import ftplib
  import os.path
  
  
  server = &quot;myserver.host.com&quot;
  user = &quot;admin@mywebsite.com&quot;
  password = &quot;mypassword&quot;
  ftpdirectory = &quot;/ftpdir&quot;
  
  filestotransfer = [
      &quot;/home/user/Desktop/file1.csv&quot;,
      &quot;/home/user/Desktop/file2.csv&quot;,
      &quot;/home/user/Desktop/file3.csv&quot;,
      &quot;/home/user/Desktop/file4.csv&quot;,
      &quot;/home/user/Desktop/file5.csv&quot;,
  ]
  for i in filestotransfer:
      try:
          with ftplib.FTP(server,timeout=10) as ftp:
              print('logging in')
              ftp.login(user, password)
      
      
              with open(i, &quot;rb&quot;) as fp:
                  dest_path = os.path.join(ftpdirectory, os.path.basename(i))
                  ftp.storbinary(f&quot;STOR {dest_path}&quot;, fp)
                  print('completed sending {}'.format(i))
      
              ftp.close()
              
              
      except:
          print('timedout')
          
  </code></pre>