python实现ftp上传
#!/usr/bin/python2.7
serviceip12='172.16.64.12'
serviceip13='172.16.64.13'
user='ebossapp'
password12=',Mb(Jo0@'
password13='0mf[TE]0'
remoutpath='/ebossdata02/eboss/fileservice/bass/mms/'
destdir='/ebossdata02/eboss/fileservice/bass/bak/'
import os
import shutil
import time
from ftplib import FTP
#list local dir file name.
listdir=os.listdir(remoutpath)
#define connect.
def ftpconnect12():
ftp=FTP()
ftp.connect(serviceip12,21)
ftp.login(user,password12)
return ftp
def ftpconnect13():
ftp=FTP()
ftp.connect(serviceip13,21)
ftp.login(user,password13)
return ftp
#Put file function.
def putfile12():
ftp = ftpconnect12()
for localfile in listdir:
bufsize = 4096
file_handle=open(remoutpath+localfile,"rb+")
ftp.storbinary('STOR '+remoutpath+localfile,file_handle,bufsize)
file_handle.flush()
ftp.close()
def putfile13():
ftp = ftpconnect13()
for localfile in listdir:
bufsize = 4096
file_handle=open(remoutpath+localfile,"rb+")
ftp.storbinary('STOR '+remoutpath+localfile,file_handle,bufsize)
file_handle.flush()
ftp.close()
#Clean file
def cleanfile():
for localfile in listdir:
fpath,fname=os.path.split(localfile)
shutil.move(remoutpath+localfile,destdir+fname)
if __name__=="__main__":
putfile12()
if __name__=="__main__":
putfile13()
if __name__=="__main__":
cleanfile()
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341