ftp upload tool download, ftp upload tool download tutorial, how to regularly back up files to ftp server?

Keywords: Operation & Maintenance ftp Python Windows Linux

Introduction to ftp transmission tools

iis7 service management tool is a powerful FTP software with excellent interactive interface and powerful functions. It supports FTP functions such as regular upload and download, regular backup, automatic update, batch upload and download, FTP multi site management, online editing, etc. At the same time, it also supports batch operation and management of windows and linux system servers, and it can also be used as a tool for VNC client and vps connection, and also supports batch operation. The software is small in size, free of installation and has many functions. It is recommended to use it.

1. Use of FTP transfer tools

**Download address: IIS7 server management tools

  • Add ftp server information

Operation steps

  • Step 1: click the "upload and download" button in the main program diagram;
  • Step 2: click "Ftp";
  • Step 3: click "add";
  • Step 4: fill in Ftp information in the pop-up server information box. Note: FIP ip port, account number and password are required;
  • Step 5: select the FTP server to open;
  • Step 6: Click to open it. See the FTP rendering immediately.

Upload file

Operation steps

  • Step 1: select multiple files to upload (press ctrl to select multiple files), right-click to upload.

  • Step 2: wait for the file to be uploaded.

  • Step 3: after the upload is completed, the right window can view the uploaded files or folders.

2. Regularly upload files to ftp server

1. First install Python on the computer, check Add Python 3.7 to PATH, and the environment variables will be added automatically after the software installation.

  1. Modify python code as needed.
# -*- coding:utf-8 -*-
"""
FTP Common operations
"""
from ftplib import FTP
import os
import datetime
import time
class FTP_OP(object):
    def __init__(self, host, username, password, port):
        """
        //Initialize ftp
        :param host: ftp host ip
        :param username: ftp user name
        :param password: ftp password
        :param port:  ftp Port (default 21)
        """
        self.host = host
        self.username = username
        self.password = password
        self.port = port
    def ftp_connect(self):
        """
        //Connect ftp
        :return:
        """
        ftp = FTP()
        ftp.set_debuglevel(0)  # Do not turn on debugging mode
        ftp.connect(host=self.host, port=self.port)  # Connect ftp
        ftp.login(self.username, self.password)  # Log in to ftp
        return ftp
    def download_file(self, ftp_file_path, dst_file_path, temp_ftp_file_name):
        """
        //Download files from ftp to local
        :param ftp_file_path: ftp Download file path
        :param dst_file_path: Local storage path
        :return:
        """        
        buffer_size = 10240  #The default is 8192
        ftp = self.ftp_connect()
        #print ftp.getwelcome()  #Display login ftp information
        file_list = ftp.nlst(ftp_file_path)
        for file_name in file_list:
                ftp_file = os.path.join(ftp_file_path, file_name)
                file_name=os.path.basename(file_name)
                write_file = os.path.join(dst_file_path+file_name)
                #print write_file
                if file_name.find(temp_ftp_file_name)>-1 and not os.path.exists(write_file):
                        print "file_name:"+write_file
                        #ftp_file = os.path.join(ftp_file_path, file_name)
                        #write_file = os.path.join(dst_file_path, file_name)
                        with open(write_file, "wb") as f:
                                ftp.retrbinary('RETR {0}'.format(ftp_file), f.write, buffer_size)
                        f.close()
        ftp.quit()
        
if __name__ == '__main__':
  		#FTP server IP
        host = "***"
         #account number
        username = "***"  
         # password
        password = "***" 
         # port
        port = "21" 
        #Directory downloaded from FTP server
        ftp_file_path = "/rawdata8_2/rbdata_pt/"  
         #Download to local directory
        dst_file_path = u"G:/resources/Resource data synchronization/" 
        #Prefix of files to download
        list = ["ltexn","yhsqk"]
        #Get the date of the day before
        now_date=(datetime.date.today() + datetime.timedelta(days = -1)).strftime('%Y%m%d')        
        #print now_date
        ftp = FTP_OP(host=host, username=username, password=password, port=port)
        for pre in list:
                #print pre
                temp_ftp_file_name=pre+"_"+now_date+".csv"
                #print temp_ftp_file_name
                try:
                        ftp.download_file(ftp_file_path=ftp_file_path, dst_file_path=dst_file_path,temp_ftp_file_name=temp_ftp_file_name)
                except :
                        print 'abnormal'

3. Add a scheduled task.

  • Press win+r to call up the operation, modify the following code as required, paste it into the operation input field and click OK.

at 10:30 /every:m,t,w,th,f,s,su "D:\backupToFtp.py"

ps: the code means to run the backupToFtp.py script.

4. How to delete a scheduled task?

The win+r key calls up the operation input cmd enter.

  • Enter at to call up the task list, and enter at serial number / delete to delete the specified task.

End of tutorial.

Posted by genix2011 on Tue, 23 Jun 2020 20:56:08 -0700