Забираем по фтп файлы *.bak
python3
import ftplib,sys
def getbinary(ftp, filename, outfile):
try:
print("retrieving file "+filename+' to -> '+outfile+"...")
fout=open(outfile,'wb')
ftp.retrbinary("RETR " + filename, fout.write)
fout.close()
except:
print("somthing wrong! error")
sys.exit(2)
def getpastfilenamofdir(ftp, dir):
ftp.cwd(dir)
pastfilename=ftp.nlst('*.bak')[-1:][0]
getbinary(ftp, pastfilename, pastfilename)
ftp=ftplib.FTP('10.10.10.10')
ftp.login('user','password')
getpastfilenamofdir(ftp, 'folder1')
getpastfilenamofdir(ftp, '../folder2/folder3')
getpastfilenamofdir(ftp, '../../folder4')
ftp.close()
sys.exit(0)
python3
import ftplib,sys
def getbinary(ftp, filename, outfile):
try:
print("retrieving file "+filename+' to -> '+outfile+"...")
fout=open(outfile,'wb')
ftp.retrbinary("RETR " + filename, fout.write)
fout.close()
except:
print("somthing wrong! error")
sys.exit(2)
def getpastfilenamofdir(ftp, dir):
ftp.cwd(dir)
pastfilename=ftp.nlst('*.bak')[-1:][0]
getbinary(ftp, pastfilename, pastfilename)
ftp=ftplib.FTP('10.10.10.10')
ftp.login('user','password')
getpastfilenamofdir(ftp, 'folder1')
getpastfilenamofdir(ftp, '../folder2/folder3')
getpastfilenamofdir(ftp, '../../folder4')
ftp.close()
sys.exit(0)
Комментариев нет:
Отправить комментарий