python代码:
# coding=UTF-8
import ftplib
import os
import shutil
import traceback
import csv
from pathlib import Path
ftp_server = '10.10.10.10'
ftp_username = 'aaa'
ftp_password = 'bbb'
ftp_dir = '/info/TestInfo'
local_file1 = '/b.csv'
local_file2 = '/a.csv'
file_path1 = Path(os.path.dirname(__file__) + local_file1)
file_path2 = Path(os.path.dirname(__file__) + local_file2)
print(file_path1)
print(file_path2)
def startUploadFtp():
if file_path1.exists() and file_path2.exists():
try:
ftp = ftplib.FTP(ftp_server)
ftp.login(ftp_username, ftp_password)
ftp.cwd(ftp_dir)
ftp.encoding = 'gbk'
ftp.storbinary('STOR %s' % os.path.basename(local_file1),open(file_path1,'rb'))
ftp.storbinary('STOR %s' % os.path.basename(local_file2),open(file_path2,'rb'))
ftp.quit()
return "文件上传成功!"
except ftplib.error_perm as e:
return "文件上传失败,错误信息:" + str(e)
except Exception as e:
return "Exception 文件上传失败:" + str(e)
else:
return "上传FTP失败,本地目录下不存在:%s" % file_path1 + "或不存在:%s" % file_path2
# if __name__=='__main__':
# print(startUploadFtp())
print(startUploadFtp())
bat代码:
@echo off
setlocal enabledelayedexpansion
py -3 uploadFtp.py
pause