#!/usr/bin/python

"""
	FTP Miner - Vivek Ramachandran 
	http://www.securitytube.net
"""

import sys
from ftplib import FTP

#find the number of ftp sites entered
ftpConnection = FTP()
ftpNum = len(sys.argv) 

if ftpNum <=1 :
	print "Enter at least one Ftp site"
	sys.exit(0)

for i in range(1, ftpNum) :
	currentSite = sys.argv[i]
	
	# connect to the site 
	print "[+]Trying to connect to ftp site: " +currentSite
	try : 
		ftpConnection = FTP(currentSite)
	except :
		print "[-]Error connecting to " +currentSite
		print "Trying next site ...\n"
		continue
	
	# yipee !! connection succeeded!
	print "[+]Connection to "+ currentSite + "succeeded"

	# print the welcome message - useful to find server side software and version
	print ftpConnection.getwelcome()

	# login into the ftp server using anonymous credentials 
	try :
		ftpConnection.login('anonymous', 'anonymous@nowhere.com')
	except :
		print "[-]Anonymous login into " + currentSite + " failed!"
		print "Trying next site\n"
		continue 

	print "[+]Anonymous login succeeded!\n"

	# print a listing of files and directories in the root directory 
	
	print "[+]Listing files in the ftproot"
	
	try :
		ftpConnection.retrlines('LIST')
	except :
		print "[-]ftproot listing denied"
		print "Trying next site\n"
		continue 

	print "[+]Trying to create a random directory on the remote ftp server!"

	try :
		ftpConnection.mkd("random1213111") # some random directory 
	except :
		print "[-]Remote directory creation not allowed!"
		print "Filesystem may be read only in anonymous mode"
		print "Trying next site\n"
		continue

	print "[+]Directory creation allowed! Security warning! :)"
	print "Trying next site\n"

	ftpConnection.quit()

		
	
