工具
python3
ftplib
上传
from ftplib import FTP
ftp = FTP(host='127.0.0.1', user='test', passwd='test') #创建
ftp.cwd('/home/test/ftp/') #上传路径
fd = open('test.txt', 'rb') #以只读的方式打开要上传的文件
ftp.storbinary('STOR test.txt', fd) #上传文件
fd.close()
ftp.quit() #退出登录
ftp.close() #关闭连接
下载
from ftplib import FTP
ftp = FTP(host='127.0.0.1', user='test', passwd='test') #创建
ftp.cwd('/home/test/ftp/') #服务器下载路径
fd = open('test.txt', 'wb') #以只写的方式打开要下载的文件
ftp.retrbinary('RETR test.txt', fd.write, 2048) #下载文件
fd.close()
ftp.quit() #退出登录
ftp.close() #关闭连接