Advertisement
mblomdahl

Short snippet to demo GAE sockets

May 2nd, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. import ftplib
  2. import logging
  3.  
  4. ftp = ftplib.FTP('hostUrl', timeout=3600)
  5. ftp.login('MyUsername', 'SecretPassword')
  6. ftp.set_debuglevel(4)
  7. filename = None
  8. for entry in ftp.nlst():
  9.     match = re.match(r'Customer_\d{5,6}\.txt', entry)
  10.     if match:
  11.         filename = match.string
  12. src_file = cStringIO.StringIO()
  13.  
  14. def _callback_gen():
  15.     total_len = [0]
  16.  
  17.     def callback(data):
  18.         total_len[0] += len(data)
  19.         src_file.write(data)
  20.         if ((time.time() - starttime[0]) * 1000) > 6e4:
  21.             logging.info('Bytes read: %i/%i' % (len(data), total_len[0])
  22.             ftp.sendcmd('NOOP')
  23.     return callback
  24.  
  25. ftp.retrbinary('RETR %s' % filename, callback_gen(), blocksize=131072)
  26.  
  27. ftp.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement