Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ftplib
- import logging
- ftp = ftplib.FTP('hostUrl', timeout=3600)
- ftp.login('MyUsername', 'SecretPassword')
- ftp.set_debuglevel(4)
- filename = None
- for entry in ftp.nlst():
- match = re.match(r'Customer_\d{5,6}\.txt', entry)
- if match:
- filename = match.string
- src_file = cStringIO.StringIO()
- def _callback_gen():
- total_len = [0]
- def callback(data):
- total_len[0] += len(data)
- src_file.write(data)
- if ((time.time() - starttime[0]) * 1000) > 6e4:
- logging.info('Bytes read: %i/%i' % (len(data), total_len[0])
- ftp.sendcmd('NOOP')
- return callback
- ftp.retrbinary('RETR %s' % filename, callback_gen(), blocksize=131072)
- ftp.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement