创建python脚本如下
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkrds.request.v20140815.DescribeBackupsRequest import DescribeBackupsRequest
import sys
import requests
import os
from ctypes import *
import ftplib
import time
from ftplib import FTP
import shutil
localtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
ip = '192.168.130.224'
username = 'yoan'
password = 'Ver018'
remotepath = '\\backup\\data\\V2.0\\'+localtime+'.tar.gz'
filePath = 'G:\\data_bak\mysql_shell'
localpath1 = 'G:\\data_bak\\mysql_shell\\down_mysql\\'
os.listdir(filePath)
for i,j,k in os.walk(filePath):
print (k[0])
localpath = localpath1 + k[0]
print (localpath)
def ftp_connect(host, username, password):
ftp = FTP()
ftp.connect(host, 21)
ftp.login(username, password)
return ftp
def upload_file(ftp, remotepath, localpath):
bufsize = 1024
fp = open(localpath, 'rb')
ftp.storbinary('STOR ' + remotepath, fp, bufsize)
ftp.set_debuglevel(0)
fp.close()
if __name__ == "__main__":
ftp = ftp_connect(ip, username , password)
upload_file(ftp,remotepath,localpath)
ftp.quit()
os.remove(localpath)
print("ok!")