#if anonymous can login from ftplib import FTP,error_perm
deftry_login(IP): f=FTP(IP) try: f.login() print"Current working directory:", f.pwd() f.quit() except error_perm: print'error' return#ignore non-directories and ones we cannot enter f = open("ip.txt",'r') all_ip = f.read().splitlines() print all_ip for i in all_ip: print i try_login(i) print'-----------'
修改下try的代码段,列出ip.txt中,可以匿名登陆的ip。
1 2 3 4 5 6 7 8 9 10
f.login() print"Current working directory:", f.pwd()