VegaS1234

SIMPLE DOWNLOAD FROM FTP

Nov 25th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. import ftplib
  2.  
  3. def ftp_download(dir_path, ftp_file):
  4.     try:
  5.         ftp = ftplib.FTP('m2tec.net')
  6.         ftp.login(user = 'user', passwd = 'password')
  7.         ftp.cwd('/public_html/{0}'.format(dir_path))
  8.        
  9.         ftp.retrbinary('RETR {0}'.format(ftp_file), open(ftp_file, 'wb').write, 1024)
  10.         ftp.storbinary('STOR {0}'.format(ftp_file), open(ftp_file, 'rb'))
  11.         ftp.quit()
  12.  
  13.         print ('Succes download file: {0}'.format(ftp_file))
  14.  
  15.     except Exception as ftp_error:
  16.         print (ftp_error)
  17.  
  18. print ('Welcome to ftplib!')
  19. dir_path = input('Type path location.\n Example: {0}: '.format('wp-content/js_composer/ or None for dir <public_html>'))
  20. ftp_file = input('Type ftp_file.\n Example: {0}: '.format('js_composer.php'))
  21.  
  22. ftp_download(['', dir_path][dir_path is not 'None'], ftp_file)
Add Comment
Please, Sign In to add comment