python 從遠(yuǎn)程服務(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'
運(yùn)行:python getServerLog.py
- 詳解用Python實(shí)現(xiàn)自動(dòng)化監(jiān)控遠(yuǎn)程服務(wù)器
- python利用paramiko連接遠(yuǎn)程服務(wù)器執(zhí)行命令的方法
- 用python寫個(gè)自動(dòng)SSH登錄遠(yuǎn)程服務(wù)器的小工具(實(shí)例)
- Python使用Paramiko模塊編寫腳本進(jìn)行遠(yuǎn)程服務(wù)器操作
- python使用socket連接遠(yuǎn)程服務(wù)器的方法
- python檢測(cè)遠(yuǎn)程服務(wù)器tcp端口的方法
- python 從遠(yuǎn)程服務(wù)器下載東西的代碼
- python程序調(diào)用遠(yuǎn)程服務(wù)的步驟詳解
相關(guān)文章
Python利用帶權(quán)重隨機(jī)數(shù)解決抽獎(jiǎng)和游戲爆裝備問題
帶權(quán)重隨機(jī)數(shù)即是隨機(jī)數(shù)各個(gè)區(qū)間段被抽中的概率根據(jù)權(quán)重而不同,這里我們就來看一下Python利用帶權(quán)重隨機(jī)數(shù)解決抽獎(jiǎng)和游戲爆裝備問題的方法,首先還是來進(jìn)一步解釋帶權(quán)隨機(jī)數(shù):2016-06-06對(duì)Keras自帶Loss Function的深入研究
這篇文章主要介紹了對(duì)Keras自帶Loss Function的深入研究,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05python腳本生成caffe train_list.txt的方法
下面小編就為大家分享一篇python腳本生成caffe train_list.txt的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-04-04Python模擬登錄驗(yàn)證碼(代碼簡(jiǎn)單)
這篇文章主要介紹了Python模擬登錄驗(yàn)證碼(代碼簡(jiǎn)單)的相關(guān)資料,需要的朋友可以參考下2016-02-02python調(diào)用機(jī)器喇叭發(fā)出蜂鳴聲(Beep)的方法
這篇文章主要介紹了python調(diào)用機(jī)器喇叭發(fā)出蜂鳴聲(Beep)的方法,實(shí)例分析了Python調(diào)用winsound模塊的使用技巧,需要的朋友可以參考下2015-03-03Python實(shí)現(xiàn)字符串格式化的方法小結(jié)
本篇文章主要介紹了Python實(shí)現(xiàn)字符串格式化的方法小結(jié),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02Python中使用多進(jìn)程來實(shí)現(xiàn)并行處理的方法小結(jié)
本篇文章主要介紹了Python中使用多進(jìn)程來實(shí)現(xiàn)并行處理的方法小結(jié),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08