我正在尝试使用Python中的ftplib将文件上传到我的FTP服务器。 我收到错误OSError: [Errno 0] Error尝试从ftplib上传具有storbinary()函数的文件时出错。 它可以与任何其他客户端一起使用(与FileZilla Client和WinSCP一起尝试)。

这是我的代码( args只是一个包含来自argparse模块的参数的名称空间):

ftp = FTP_TLS() ftp.connect(args.host, args.port) ftp.set_pasv(True) ftp.login(user=args.user, passwd=args.password)  ftp.prot_p()  with open('COM.e', 'rb') as f:     ftp.storbinary('STOR /commands/COM.e', f)  ftp.quit() 

我收到此错误:

Traceback (most recent call last):   File "c:\Users\xxxx\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\ptvsd_launcher.py", line 43, in <module>     main(ptvsdArgs)   File "c:\Users\xxxx\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 432, in main     run()   File "c:\Users\xxxx\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 316, in run_file    runpy.run_path(target, run_name='__main__')   File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 263, in run_path     pkg_name=pkg_name, script_name=fname)   File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 96, in _run_module_code     mod_name, mod_spec, pkg_name, script_name)   File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 85, in _run_code     exec(code, run_globals)   File "C:\Users\xxxx\Documents\Coding Projects\KeyLogger\Tools\sendcommands.py", line 84, in <module>     main()   File "C:\Users\xxxx\Documents\Coding Projects\KeyLogger\Tools\sendcommands.py", line 34, in main     ftp.storbinary('STOR /souvlaki/' + COMMANDS_FILE, f)   File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\ftplib.py", line 504, in storbinary     with self.transfercmd(cmd, rest) as conn:   File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\ftplib.py", line 399, in transfercmd     return self.ntransfercmd(cmd, rest)[0]   File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\ftplib.py", line 801, in ntransfercmd     server_hostname=self.host)   File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 423, in wrap_socket     session=session   File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 870, in _create     self.do_handshake()   File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 1139, in do_handshake     self._sslobj.do_handshake() OSError: [Errno 0] Error 

如果有帮助,这是服务器的输出(FileZilla,使用通过TLS的显式FTP):

Logged on (000426)30/11/2019 13:07:43 - (not logged in) (XX.XX.XXX.XXX)> Connected on port 2121, sending welcome message... (000426)30/11/2019 13:07:43 - (not logged in) (XX.XX.XXX.XXX)> 220 The Kebab Project (000426)30/11/2019 13:07:43 - (not logged in) (XX.XX.XXX.XXX)> AUTH TLS (000426)30/11/2019 13:07:43 - (not logged in) (XX.XX.XXX.XXX)> 234 Using authentication type TLS (000426)30/11/2019 13:07:44 - (not logged in) (XX.XX.XXX.XXX)> TLS connection established (000426)30/11/2019 13:07:44 - (not logged in) (XX.XX.XXX.XXX)> USER root (000426)30/11/2019 13:07:44 - (not logged in) (XX.XX.XXX.XXX)> 331 Password required for root (000426)30/11/2019 13:07:44 - (not logged in) (XX.XX.XXX.XXX)> PASS ******** (000426)30/11/2019 13:07:44 - root (XX.XX.XXX.XXX)> 230 Logged on (000426)30/11/2019 13:07:44 - root (XX.XX.XXX.XXX)> PBSZ 0 (000426)30/11/2019 13:07:44 - root (XX.XX.XXX.XXX)> 200 PBSZ=0 (000426)30/11/2019 13:07:44 - root (XX.XX.XXX.XXX)> PROT P (000426)30/11/2019 13:07:44 - root (XX.XX.XXX.XXX)> 200 Protection level set to P (000426)30/11/2019 13:07:44 - root (XX.XX.XXX.XXX)> TYPE I (000426)30/11/2019 13:07:44 - root (XX.XX.XXX.XXX)> 200 Type set to I (000426)30/11/2019 13:07:44 - root (XX.XX.XXX.XXX)> PASV (000426)30/11/2019 13:07:44 - root (XX.XX.XXX.XXX)> 227 Entering Passive Mode (107,171,223,177,25,89) (000426)30/11/2019 13:07:44 - root (XX.XX.XXX.XXX)> STOR /commands/COM.e (000426)30/11/2019 13:07:44 - root (XX.XX.XXX.XXX)> 150 Opening data channel for file upload to server of "/commands/COM.e" (000426)30/11/2019 13:07:44 - root (XX.XX.XXX.XXX)> 450 TLS session of data connection has not resumed or the session does not match the control connection (000426)30/11/2019 13:07:44 - root (XX.XX.XXX.XXX)> disconnected. 

我究竟做错了什么? 谢谢。

未解决问题?本站智能推荐: