【发布时间】:2020-11-18 01:39:50
【问题描述】:
我正在尝试从 Whonix 操作系统内将文件上传到服务器。我能够在 Whonix 中使用 Filezilla 成功地做到这一点,所以我不太确定 Python 代码为什么不起作用。
from ftplib import FTP, FTP_TLS
import os
ftp = FTP_TLS()
ftp.set_debuglevel(2)
ftp.connect('ftp.server.com', 21)
ftp.login('Username', 'Password')
item_name = 'myfile.mp4'
item_path = os.path.abspath(item_name)
fp = open(item_path, 'rb')
ftp.storbinary('STOR {}'.format(item_name), fp, 8192)
fp.close()
有人知道我应该如何更改 Python 代码才能从 Whonix 中成功上传文件吗?作为参考,当我直接从 Windows 中运行 Python 代码时,它可以工作。只有当我在 Whonix 中尝试它时它才会失败,我不知道为什么。
这是我得到的错误,我不明白:
*get* '220-This is a private system - No anonymous login\n'
*get* '220-IPv6 connections are also welcome on this server.\n'
*get* '220 You will be disconnected after 30 minutes of inactivity.\n'
*resp* '220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------\n220-You are user number 17 of 50 allowed.\n220-Local time is now 01:28. Server port: 21.\n220-This is a private system - No anonymous login\n220-IPv6 connections are also welcome on this server.\n220 You will be disconnected after 30 minutes of inactivity.'
*cmd* 'AUTH TLS'
*put* 'AUTH TLS\r\n'
*get* '234 AUTH TLS OK.\n'
*resp* '234 AUTH TLS OK.'
Traceback (most recent call last):
File "test.py", line 8, in <module>
ftp.login('Username', 'Password')
File "/usr/lib/python3.7/ftplib.py", line 749, in login
self.auth()
File "/usr/lib/python3.7/ftplib.py", line 761, in auth
server_hostname=self.host)
File "/usr/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/usr/lib/python3.7/ssl.py", line 853, in _create
self.do_handshake()
File "/usr/lib/python3.7/ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: DH_KEY_TOO_SMALL] dh key too small (_ssl.c:1056)
【问题讨论】:
标签: python python-3.x networking ftp