使用Python ftplib将文件夹中的文件上载到FTP
我正试图上传一个目录中包含的一堆文件 代码没有失败,但似乎也不起作用 我的代码如下:使用Python ftplib将文件夹中的文件上载到FTP,python,ftp,upload,ftplib,Python,Ftp,Upload,Ftplib,我正试图上传一个目录中包含的一堆文件 代码没有失败,但似乎也不起作用 我的代码如下: import ftplib FTP_HOST = "host" FTP_USER = "user" FTP_PASS = "pass" ftp = ftplib.FTP(FTP_HOST, FTP_USER, FTP_PASS) ftp.encoding = "utf-8" dirFTP = "dirPath&quo
import ftplib
FTP_HOST = "host"
FTP_USER = "user"
FTP_PASS = "pass"
ftp = ftplib.FTP(FTP_HOST, FTP_USER, FTP_PASS)
ftp.encoding = "utf-8"
dirFTP = "dirPath"
toFTP = os.listdir(dirFTP)
for filename in toFTP:
filePath = os.path.join(dirFTP, filename)
with open(filePath, "rb") as file:
ftp.storbinary(f"STOR {filePath}", file)
ftp.quit()
我哪里做错了
提前谢谢。好的。我的代码工作正常 代码是:
import ftplib
FTP_HOST = "host"
FTP_USER = "user"
FTP_PASS = "pass"
ftp = ftplib.FTP(FTP_HOST, FTP_USER, FTP_PASS)
ftp.encoding = "utf-8"
dirFTP = "dirPath"
toFTP = os.listdir(dirFTP)
for filename in toFTP:
with open(os.path.join(dirFTP,filename), 'rb') as file: #Here I open the file using it's full path
ftp.storbinary(f'STOR {filename}', file) #Here I store the file in the FTP using only it's name as I intended
ftp.quit()
感谢您的帮助。在循环之前添加
print(toFtp)
,或者在调试器下运行并在那里进行检查。