我想遍历本地计算机上一个文件夹中的一组文件,并仅上传文件名包含“Service_Areas”的文件到我的 FTP 网站,使用以下代码(Python 3.6.1 32 位,Windows 10 64 位):
我正在尝试通过以下代码遍历本地计算机上的文件夹中的一组文件,并仅上传名称中包含“Service_Areas”的文件到我的 FTP 站点:
ftp = FTP('ftp.ftpsite.org')
username = ('username')
password = ('password')
ftp.login(username,password)
ftp.cwd(username.upper())
ftp.cwd('2017_05_02')
for i in os.listdir('C:\FTP_testing'):
if i.startswith("Service_Area"):
local_path = os.path.join('C:\FTP_testing',i)
file = open(local_path,'rb')
ftp.storbinary("STOR " + i, open(file, 'rb'))
file.close()
continue
else:
print('nope')
ftp.quit()
但是我遇到了这个错误:Traceback (most recent call last):
File "C:\Users\user\Desktop\Test1.py", line 32, in <module>
ftp.storbinary("STOR " + str(i), open(file, 'rb'))
TypeError: expected str, bytes or os.PathLike object, not _io.BufferedReader
有什么建议吗?