python 表单 直接上传到 ftp
表单 直接上传到 ftp
from ftplib import FTP def upload_ftp(): # 获取上传的文件 file = request.files['file'] # 连接FTP服务器 host = '192.168.1.23' user = 'test' passwd = 'test888' ftppath = '/abc/' ftp = FTP(host) ftp.login(user=user, passwd=passwd) try: # 切换到指定目录 ftp.cwd(ftppath) # 上传文件 ftp.storbinary('STOR ' + file.filename, file) return '文件上传成功' except Exception as e: return '文件上传失败:' + str(e) finally: # 关闭FTP连接 ftp.quit()