【发布时间】:2014-11-03 13:10:46
【问题描述】:
我正在使用 python 套接字连接到 ftp.reiris.es,但在发送数据后我没有收到我期望的答案。我用我的代码和答案更好地解释了这一点: 这是我的代码(test.py)
#!/usr/bin/env python
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "Socket Created"
port = 21
host = "ftp.rediris.es"
ip = socket.gethostbyname(host)
print ip
print "ip of " +host+ " is " +ip
s.connect ((ip, port))
print "Socket Connected to "+host+" on ip "+ ip
message = "HELP\r\n"
s.sendall(message)
reply = s.recv(65565)
print reply
这是我运行代码时的答案:
python test.py
Socket Created
130.206.1.5
ip of ftp.rediris.es is 130.206.1.5
Socket Connected to ftp.rediris.es on ip 130.206.1.5
220- Bienvenido al FTP anónimo de RedIRIS.
220-Welcome to the RedIRIS anonymous FTP server.
220 Only anonymous FTP is allowed here
这是我所期望的:
telnet
telnet> open ftp.rediris.es 21
Trying 130.206.1.5...
Connected to zeppo.rediris.es.
Escape character is '^]'.
220- Bienvenido al FTP anónimo de RedIRIS.
220-Welcome to the RedIRIS anonymous FTP server.
220 Only anonymous FTP is allowed here
HELP
214-The following SITE commands are recognized
ALIAS
CHMOD
IDLE
UTIME
我已经在通往 www.google.com 的端口 80 上尝试过这个,发送一个 GET / HTTP/1.1\r\n\r\n 并且完美地看到了标题。 发生什么了?我没有将命令直接发送到服务器吗?提前谢谢你
【问题讨论】:
-
有关 FTP 协议的描述,请参阅 RFC959 并实现您在其中找到的内容。不要试图猜测协议。
标签: python sockets tcp ftp serversocket