#!/usr/bin/python # -*-coding:utf-8 -*- from ftplib import FTP def ftpconnect(host,username,password): ftp=FTP() ftp.connect(host,7005) ftp.login(username,password) return ftp #从ftp下载 def downloadfile(ftp,remotepath,localpath): bufsize = 1024 fp=open(localpath,'wb') ftp.retrbinary('RETR ' + remotepath,fp.write,bufsize) ftp.set_debuglevel(0) fp.close() def uploadfile(ftp,remotepath,localpath): bufsize=1024 fp=open(localpath,'rb') ftp.storbinary('STOR ' + remotepath,fp,bufsize) ftp.set_debuglevel(0) fp.close() if __name__=='__main__': ftp=ftpconnect("60.174.203.118","ahwater","1qaz@WSX") #uploadfile(ftp,"D:\\秦瑞-工作\\BugReport.txt","BugReport-bak.txt") uploadfile(ftp,"py_ftp.py","D:\py_ftp.py") ftp.quit()