【发布时间】:2026-01-16 07:05:02
【问题描述】:
我目前的python代码:
import ftplib
import hashlib
import urllib
def ftp():
hashing="123"
ftp = ftplib.FTP('localhost','kevin403','S$ip1234')
ftp.cwd('/var/www/html/image')
m=hashlib.md5()
file = open('Desktop/test.png','rb')
m.update(hashing)
dd = m.hexdigest()
ftp.storbinary('STOR '+dd+ '.png', file)
file.close()
ftp.quit()
我得到了由 test.png、test1.png 和 test2.png 组成的不同文件名。我想打开文件并在任何文件打开时存储它。 我尝试使用 * 星号,但出现错误:
file = open('Desktop/*.png, 'rb')
【问题讨论】:
-
我很困惑,你有
test1.png, test2.png,等文件吗?如果是这样,那么首先为他们提供全局并列出他们?然后循环遍历列表。可能是我理解错了,你的问题不是很清楚。 -
这 3 个文件在我的桌面上。
-
您希望 ftp 函数查找所有这些文件还是每次调用该函数处理一个文件?
-
是的,我想这样做
-
在下面查看我的答案
标签: python python-2.7 ftp