Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ftplib
- from datetime import datetime
- server_ip = <server ip as a string>
- ftp_port = <ftp port as int>
- username = <username as string>
- password = <password as string>
- try:
- ftp = ftplib.FTP()
- ftp.connect(host=server_ip,port=ftp_port)
- ftp.login(user=username,passwd=password)
- except Exception as e:
- print(e)
- else:
- file_path = '/mnt/net_store/Data/geeks/ylands/serverbackup/'
- orig_file = 'SessionSave.ylandsgame'
- new_file = 'SessionSave_{0}.ylandsgame'.format(datetime.now().strftime('%Y%m%d_%H%M%S'))
- try:
- ftp.rename(orig_file,new_file)
- with open('{0}{1}'.format(file_path,new_file), 'wb') as f:
- ftp.retrbinary('RETR {0}'.format(new_file), f.write)
- except ftplib.error_perm as e:
- print(e)
- else:
- print('{0} Backup complete.'.format(new_file))
- ftp.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement