Use Python for file backup

Source: Internet
Author: User
Tags ftp file

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.