Python Sockets connect to FTP don't receive what I expect -
Python Sockets connect to FTP don't receive what I expect -
i using python socket connect ftp.rediris.es , don't receive reply expect after sending data. explain improve code , answers: code (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+ " " +ip s.connect ((ip, port)) print "socket connected "+host+" on ip "+ ip message = "help\r\n" s.sendall(message) reply = s.recv(65565) print reply
this reply when run code:
python test.py socket created 130.206.1.5 ip of ftp.rediris.es 130.206.1.5 socket connected ftp.rediris.es on ip 130.206.1.5 220- bienvenido al ftp anónimo de rediris. 220-welcome rediris anonymous ftp server. 220 anonymous ftp allowed here
and expect:
telnet telnet> open ftp.rediris.es 21 trying 130.206.1.5... connected zeppo.rediris.es. escape character '^]'. 220- bienvenido al ftp anónimo de rediris. 220-welcome rediris anonymous ftp server. 220 anonymous ftp allowed here help 214-the next site commands recognized alias chmod idle utime
i have tried on port 80 towards www.google.com, sending / http/1.1\r\n\r\n , seen header perfectly. happens¿? not sending command right server¿? give thanks in advance
you may check if lastly line of 220 anonymous ftp allowed here
has been received before sending help
message, read_until
in telnetlib.
like this, works me:
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+ " " +ip s.connect ((ip, port)) print "socket connected "+host+" on ip "+ ip reply = '' while true: message = "help\r\n" reply += s.recv(1024) if not reply: break if '220 anonymous ftp allowed here' in reply: s.sendall(message) break reply += s.recv(65535) print reply
printout:
socket created 130.206.1.5 ip of ftp.rediris.es 130.206.1.5 socket connected ftp.rediris.es on ip 130.206.1.5 220- bienvenido al ftp anónimo de rediris. 220-welcome rediris anonymous ftp server. 220 anonymous ftp allowed here 214-the next site commands recognized alias chmod idle utime 214 pure-ftpd - http://pureftpd.org/
that said though, not exclusively sure why haven't chosen more suitable modules ftplib
or telnetlib
begin with.
python sockets tcp ftp serversocket
Comments
Post a Comment