import ftplib
class ftpclass:
def __init__(self,HOST,USER,PASS):
self.HOST=HOST
self.USER=USER
self.PASS=PASS
def ftplogin(self):
fsock=ftplib.FTP(self.HOST)
fsock.login(self.USER,self.PASS)
return fsock
def ftpls(self,fsock):
print fsock.retrlines('LIST')
def upload(self,fsock,file):
fsock.storlines("STOR " + filen, open(file)) # 上传文本文件
# fsock.storbinary("STOR " + file, open(file, 'rb'), 1024) # 上传二进制文件
if __name__=='__main__':
ftp1 = ftpclass('192.168.1.10','ftp4','123456')
conn = ftp1.ftplogin()
# ftp1.upload(conn,'1.jpg')
# ftp1.upload(conn,'3.txt')
conn.quit()
阅读(489) | 评论(0) | 转发(0) |