Skip to content

Instantly share code, notes, and snippets.

@studiawan
Last active September 1, 2017 19:32
Show Gist options
  • Save studiawan/02aba8a9479f9db99831 to your computer and use it in GitHub Desktop.
Save studiawan/02aba8a9479f9db99831 to your computer and use it in GitHub Desktop.
Connect to FTP server using raw socket
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect (('localhost', 21))
commands = ['USER hudan\r\n', 'PASS 123\r\n', 'HELP\r\n', 'QUIT\r\n']
i = 1
while True:
try:
if i > len(commands):
msg = str(s.recv(1024))
print msg.strip()
break
s.send(commands[i-1])
msg = str(s.recv(1024))
print msg.strip()
i += 1
except socket.error, exc:
# print exc
s.close()
break
@SRJanel
Copy link

SRJanel commented Sep 1, 2017

"socket.SOCK_STREAM" <-- does not look like a RAW socket to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment