使用 FTP.storbinary 将文件上传到 Python 中的 FTP 时出现“500 未知命令”

Getting "500 Unknown command" when uploading a file to FTP in Python with FTP.storbinary

我正在尝试将文件上传到 FTP。我正在尝试在 files.000webhost.com 上将文件上传到 /public_html,但我一直收到 ftplib.error_perm: 500 Unknown command

我的代码如下:

import ftplib
session = ftplib.FTP('files.000webhost.com','hazaaay','dwadawdadw')
file = r'C:\Users\Downloads\A csv\a csv1.csv','b'                  # file to send
session.storbinary('a csv1.csv', file)     # send the file
file.close()                                    # close file and FTP
session.quit()

尽管给出了未解决的参考,它在控制台中表示该进程以退出代码 0 结束,但它没有显示在 FileZilla 中。有任何想法吗? 谢谢。

您必须在 FTP.storbinary call 中指定命令。

Store a file in binary transfer mode. command should be an appropriate STOR command: "STOR filename".

session.storbinary('STOR a csv1.csv', file)