python - 如何使用python通过FT上传许多文件?
问题描述
我有很多文件(可能是大量文件),我想上传到我的 FTP 服务器。
我应该如何实施?通过只使用一个连接直到错误或每次关闭/打开..我还需要检查 FTP 服务器是否活动。我使用 ftplib。
from ftplib import FTP
def ftp_upload(remotefile):
with open(localfile, 'rb') as f:
ftp.storlines('STOR %s' % remotefile, f)
#ftp.close()
ftp = FTP()
ftp.set_debuglevel(2)
retry = False
while True:
try:
if retry:
/* find list of files * remote_path="some_file"/
ftp_upload(remote_path)
else:
ftp.connect('host', port)
ftp.login('user','pass')
retry=True
except Exception as e:
print("error({0}): {1}".format(e.errno, e.strerror))
rint("Retrying...")
retry = False
解决方案
推荐阅读
- discord.py - Discord Bot 可以拥有 gmail 帐户吗?
- c# - DataGridView 多线程更新崩溃
- sql - 如何使用linq在excel上导出数据?
- python - 如何根据 Tkinter 中窗口的大小不截断长文本
- python - 为什么没有显示python plotly box-plot y轴?
- android-studio - 如何在android studio中解决这个问题?
- xamarin.forms - 设置列表视图项模板的背景颜色和列表背景颜色时,Xamarin Forms Listview 选定项背景颜色丢失
- flutter - 如何在颤动中返回现有的平台视图
- vue.js - 无法使用 jspdf 将 vue 组件转换为 pdf
- javascript - Fabric JS折线点更新问题