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寫(xiě)個(gè)自動(dòng)SSH登錄遠(yuǎn)程服務(wù)器的小工具(實(shí)例)
- Python使用Paramiko模塊編寫(xiě)腳本進(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)文章
vscode搭建python Django網(wǎng)站開(kāi)發(fā)環(huán)境的示例
本文主要介紹了vscode搭建python Django網(wǎng)站開(kāi)發(fā)環(huán)境的示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02
Python+Socket實(shí)現(xiàn)基于UDP協(xié)議的局域網(wǎng)廣播功能示例
這篇文章主要介紹了Python+Socket實(shí)現(xiàn)基于UDP協(xié)議的局域網(wǎng)廣播功能,結(jié)合實(shí)例形式分析了Python+socket實(shí)現(xiàn)UDP協(xié)議廣播的客戶(hù)端與服務(wù)器端功能相關(guān)操作技巧,需要的朋友可以參考下2017-08-08
sqlalchemy實(shí)現(xiàn)時(shí)間列自動(dòng)更新教程
這篇文章主要介紹了sqlalchemy實(shí)現(xiàn)時(shí)間列自動(dòng)更新教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09
使用python實(shí)現(xiàn)簡(jiǎn)單爬取網(wǎng)頁(yè)數(shù)據(jù)并導(dǎo)入MySQL中的數(shù)據(jù)庫(kù)
這篇文章主要為大家詳細(xì)介紹了如何使用 python 實(shí)現(xiàn)簡(jiǎn)單爬取網(wǎng)頁(yè)數(shù)據(jù)并導(dǎo)入 MySQL 中的數(shù)據(jù)庫(kù),對(duì)我們的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2023-06-06
Python運(yùn)行錯(cuò)誤異常代碼含義對(duì)照表
這篇文章主要介紹了Python運(yùn)行錯(cuò)誤異常代碼含義對(duì)照表,需要的朋友可以參考下2021-04-04
TensorFlow實(shí)現(xiàn)模型斷點(diǎn)訓(xùn)練,checkpoint模型載入方式
這篇文章主要介紹了TensorFlow實(shí)現(xiàn)模型斷點(diǎn)訓(xùn)練,checkpoint模型載入方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-05-05
Python socket處理client連接過(guò)程解析
這篇文章主要介紹了Python socket處理client連接過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03

