编程语言
首页 > 编程语言> > python-ftplib:被动和NAT /地址转换

python-ftplib:被动和NAT /地址转换

作者:互联网

有没有一种方法可以检测到服务器在进入被动模式时返回其专用网络地址,并将其转换为公共地址?
我无权访问服务器.

>>> # Python 2.7.3rc2
>>> from ftplib import FTP_TLS
>>> ftps = FTP_TLS()
>>> ftps.set_debuglevel(2)
>>> ftps.connect("example.com", 123)
*get* '220 Welcome to Synchrony Gateway FTP server\r\n'
*resp* '220 Welcome to Synchrony Gateway FTP server'
'220 Welcome to Synchrony Gateway FTP server'

>>> ftps.auth()
*cmd* 'AUTH TLS'
*put* 'AUTH TLS\r\n'
*get* '234 Using authentication type TLS\r\n'
*resp* '234 Using authentication type TLS'
'234 Using authentication type TLS'

>>> ftps.login("foo", "***")
*cmd* 'AUTH TLS'
*put* 'AUTH TLS\r\n'
*get* '234 AUTH command OK, waiting handshake\r\n'
*resp* '234 AUTH command OK, waiting handshake'
*cmd* 'USER foo'
*put* 'USER foo\r\n'
*get* '331 Send password please\r\n'
*resp* '331 Send password please'
*cmd* 'PASS ************'
*put* 'PASS ************\r\n'
*get* '230 User logged in, proceed\r\n'
*resp* '230 User logged in, proceed'
'230 User logged in, proceed'

>>> ftps.prot_p()
*cmd* 'PBSZ 0'
*put* 'PBSZ 0\r\n'
*get* '200 Command okay\r\n'
*resp* '200 Command okay'
*cmd* 'PROT P'
*put* 'PROT P\r\n'
*get* '200 Command okay\r\n'
*resp* '200 Command okay'
'200 Command okay'

>>> ftps.set_pasv(True)
>>> ftps.retrlines("LIST")
*cmd* 'TYPE A'
*put* 'TYPE A\r\n'
*get* '200 Type set to A\r\n'
*resp* '200 Type set to A'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering Passive Mode (192,168,17,1,195,119)\r\n'
*resp* '227 Entering Passive Mode (192,168,17,1,195,119)'

谢谢.

解决方法:

配置服务器以在外部IP上进入被动模式.

标签:python-2-7,ftplib,python
来源: https://codeday.me/bug/20191127/2075800.html