在FTP服务器上搜索指定文件

#!/usr/bin/python
#coding=utf-8
import ftplib

'''
函数检查每个文件返回默认WEB 页面文件名
并将任何发现的默认 WEB 页面文件名添加到名为 retList 的列 表中。
完成迭代这些文件之后,函数将返回这个列表。
'''
def returnDefault(ftp):
	try:
		#nlst()方法获取目录下的文件
		dirList=ftp.nlst()
	except:
		dirList=[]
		print '[-] Could not list directory contents.'
		print '[-] Skipping To Next Target.'
		return

    #返回命中文件列表
	retList=[]
	for fileName in dirList:
		#lower()方法将文件名都转换为小写的形式 
		fn=fileName.lower()
		if '.php' in fn or '.htm' in fn or '.asp' in fn:
			print '[+] Found default page: ' + fileName
			retList.append(fileName)

	if len(retList)==0:
		print '[-] Could not list directory contents.'
		print '[-] Skipping To Next Target.'

	return retList

def main():

	while  True:
		host=raw_input('[*]Host >>> ')
		if host=='bye' or host=='':
			return
		username = raw_input('[*]Username >>> ')
		password = raw_input('[*]Password >>> ')


		try:
			ftp = ftplib.FTP(host)
			ftp.login(username,password)
			returnDefault(ftp)

		except:
			print '[-] Logon failed.'

        
if __name__ == '__main__':
	main()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值