我正在使用這個python 2.7腳本來偵聽端口21.現在我需要在用戶嘗試通過ftp客戶端連接時回顯用戶名和密碼。 我應該在腳本中更改哪些內容?打印ftp名稱和密碼數據
import socket
import sys
HOST = '' # Symbolic name, meaning all available interfaces
PORT = 21 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
#Bind socket to local host and port
try:
s.bind((HOST, PORT))
except socket.error as msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
print 'Socket bind complete'
#Start listening on socket
s.listen(10)
print 'Socket now listening'
#now keep talking with the client
while 1:
#wait to accept a connection - blocking call
conn, addr = s.accept()
print 'Connected with ' + addr[0] + ':' + str(addr[1])
s.close()
現在你必須接收你的數據並解釋它。你可以使用'recv()'([see](https://docs.python.org/2/library/socket.html))。 – daouzli
Daouzli,謝謝! – peter