python 從遠程服務(wù)器下載日志文件的程序
import os
import sys
import ftplib
import socket
##################################################################
# sign in the ftp server and download the log file.
# 登陸生產(chǎn)服務(wù)器下載日志
#################################################################
def getServerLog(dir,fileName,host,userName,password):
if os.path.exists(fileName):
print '****the file '+ fileName +' has already exist! The file will be over writed'
#connect
try:
f=ftplib.FTP(host)
except (socket.error,socket.gaierror),e:
print '----ERROR:cannot reach '+host
print e
return False
#login
try:
f.login(user=userName,passwd=password)
except ftplib.error_perm ,e:
print '----ERROR:cannot login to server '+host
print e
f.quit()
return False
print '****Logged in as ' + userName + ' to server ' +host
#change folder
try:
f.cwd(dir)
except ftplib.error_perm,e:
print '----ERROR:cannot CD to %s on %s' % (dir,host)
print e
f.quit()
return False
print '**** changed to %s folder on %s' % (dir,host)
#get file
try:
f.retrbinary('RETR %s' % fileName,open(fileName,'wb').write)
except ftplib.error_perm,e:
print '----ERROR:cannot read file %s on %s' % (fileName,host)
print e
os.unlink(fileName)
return False
else:
print '****Downloaded '+ fileName +' from '+ host +' to '+os.getcwd()
f.quit()
return True
if __name__ == "__main__":
getServerLog("/userhome/root/other/temp","a.out","10.10.10.10","root","password")
print '****done'
運行:python getServerLog.py
相關(guān)文章
vscode搭建python Django網(wǎng)站開發(fā)環(huán)境的示例
本文主要介紹了vscode搭建python Django網(wǎng)站開發(fā)環(huán)境的示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02
Python+Socket實現(xiàn)基于UDP協(xié)議的局域網(wǎng)廣播功能示例
這篇文章主要介紹了Python+Socket實現(xiàn)基于UDP協(xié)議的局域網(wǎng)廣播功能,結(jié)合實例形式分析了Python+socket實現(xiàn)UDP協(xié)議廣播的客戶端與服務(wù)器端功能相關(guān)操作技巧,需要的朋友可以參考下2017-08-08
使用python實現(xiàn)簡單爬取網(wǎng)頁數(shù)據(jù)并導(dǎo)入MySQL中的數(shù)據(jù)庫
這篇文章主要為大家詳細介紹了如何使用 python 實現(xiàn)簡單爬取網(wǎng)頁數(shù)據(jù)并導(dǎo)入 MySQL 中的數(shù)據(jù)庫,對我們的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2023-06-06
TensorFlow實現(xiàn)模型斷點訓(xùn)練,checkpoint模型載入方式
這篇文章主要介紹了TensorFlow實現(xiàn)模型斷點訓(xùn)練,checkpoint模型載入方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05

