最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python 從遠程服務(wù)器下載日志文件的程序

 更新時間:2013年02月10日 10:34:45   作者:  
本文提供了一種方法,該程序可實現(xiàn)抓取服務(wù)器的日志文件到本地,根據(jù)該程序可自行擴展對日志文件的自動化分析。常用于數(shù)據(jù)挖掘、生產(chǎn)維護等

復(fù)制代碼 代碼如下:

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)文章

最新評論

宁安市| 古蔺县| 大田县| 阜新市| 道真| 通许县| 景泰县| 遂宁市| 三河市| 资兴市| 合江县| 康乐县| 水富县| 寻甸| 沧源| 凤山市| 方正县| 汝城县| 固镇县| 镇江市| 永清县| 县级市| 韶关市| 修水县| 西盟| 天峨县| 建昌县| 乌鲁木齐市| 哈巴河县| 湘阴县| 遂平县| 静海县| 田东县| 鄯善县| 赤壁市| 合肥市| 临泽县| 黎川县| 昭苏县| 定州市| 河北区|