我正在使用python套接字連接到ftp.rediris.es,並且在發送數據後我沒有收到我期望的答案。我用我的代碼和答案更好地解釋這一點: 這是我的代碼(test.py)連接到FTP的Python套接字沒有收到我期望的內容
#!/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
我試圖此端口80朝向www.google.com上,發送一個GET/HTTP/1.1 \ r \ n \ r \ n和完全看到的報頭。 會發生什麼?我是不是將命令發送給服務器?謝謝你在前進
有關FTP協議的描述,請參閱RFC959,並實現您在那裏找到的內容。不要試圖猜測協議。 – 2014-11-03 14:21:01