Use Python for file backup
1. The server needs to be backed up
Because of business needs, there is a Windows Server 2008 Server. The above files need to be backed up, but the windows cmd command is not well written. I started to write a cmd script with my head and found that I had been searching for time processing for half a day. It is really too difficult to use.
2. Use python to solve the problem
Install Python directly on Windows and run the scheduled tasks in Windows.
I searched for the ftp backup method for half a day online.
But none of them are detailed. Summary:
From ftplib import FTPftp = FTP () # Set the variable # ftp. set_debuglevel (2) # enable debug level 2 and display the ftp details. connect ("192.168.1.120", "21") # connect to the ftp server and port ftp. login ("userName", "password") # connection userName, password print (ftp. getwelcome () # print the welcome information # print (ftp. retrlines ('list/Server/path') # ftp. storbinary ('stor/Server/path/newFileName. java ', open ("/Local/path/fileName. java ", 'rb') # upload an FTP file. quit ()
Ftplib is available in python by default. Just use it.
Use ftp. storbinary ('stor/XXX ", open ("/XXX ")," rb "). Enter the server path & file name, and the local path & file name.
3. Summary
Python is really powerful. No wonder Internet companies like it.
Solved many problems on windows.
Python core programming version 2. (Wesley J. Chun). [Chinese version of hd pdf]
Python development technology details. (Zhou Wei, Zong Jie). [hd PDF scan version + book guide video + code]
Obtain Linux information using a Python script
Build a desktop algorithm transaction research environment using Python in Ubuntu
Python details: click here
Python: click here
This article permanently updates the link address: