Last active
December 1, 2015 09:50
-
-
Save studiawan/212125818945b6edf259 to your computer and use it in GitHub Desktop.
List all files and directories in FTP server home dir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect (('localhost', 21)) | |
commands = ['USER hudan\r\n', 'PASS 123\r\n', 'TYPE I\r\n', 'EPSV\r\n', 'MLSD\r\n', 'QUIT\r\n'] | |
i = 1 | |
while True: | |
try: | |
if i > len(commands): | |
msg = str(s.recv(4096)) | |
print msg.strip() | |
s.close() | |
break | |
s.send(commands[i-1]) | |
msg = str(s.recv(4096)) | |
print msg.strip() | |
if "Entering Extended Passive Mode" in msg: | |
data_port = int(msg.strip().split('|||')[1][:-2]) | |
data_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
data_sock.connect(('localhost', data_port)) | |
data = data_sock.recv(4096) | |
print data | |
i += 1 | |
except socket.error, exc: | |
print exc | |
s.close() | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment