Advertisement
dustyp

ylands_backup.py

Jan 16th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. import ftplib
  2. from datetime import datetime
  3.  
  4. server_ip = <server ip as a string>
  5. ftp_port = <ftp port as int>
  6. username = <username as string>
  7. password = <password as string>
  8.  
  9. try:
  10.     ftp = ftplib.FTP()
  11.     ftp.connect(host=server_ip,port=ftp_port)
  12.     ftp.login(user=username,passwd=password)
  13. except Exception as e:
  14.     print(e)
  15. else:
  16.     file_path = '/mnt/net_store/Data/geeks/ylands/serverbackup/'
  17.     orig_file = 'SessionSave.ylandsgame'
  18.     new_file = 'SessionSave_{0}.ylandsgame'.format(datetime.now().strftime('%Y%m%d_%H%M%S'))
  19.     try:
  20.         ftp.rename(orig_file,new_file)
  21.         with open('{0}{1}'.format(file_path,new_file), 'wb') as f:
  22.             ftp.retrbinary('RETR {0}'.format(new_file), f.write)
  23.     except ftplib.error_perm as e:
  24.         print(e)
  25.     else:
  26.         print('{0} Backup complete.'.format(new_file))
  27.  
  28.     ftp.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement