国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python 從遠程服務器下載日志文件的程序

2020-02-23 04:50:24
字體:
來源:轉載
供稿:網友

代碼如下:
import os
import sys
import ftplib
import socket

##################################################################
# sign in the ftp server and download the log file.
# 登陸生產服務器下載日志
#################################################################
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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 麦盖提县| 婺源县| 眉山市| 平舆县| 毕节市| 扎鲁特旗| 登封市| 靖江市| 榆中县| 朝阳县| 鹤峰县| 松桃| 辽阳市| 新和县| 连山| 九江县| 北票市| 宁明县| 青神县| 平舆县| 慈溪市| 景德镇市| 五大连池市| 永昌县| 射洪县| 彭州市| 黄石市| 临泽县| 盐山县| 高密市| 龙口市| 邯郸市| 伊通| 会同县| 六盘水市| 巩义市| 胶南市| 绵阳市| 关岭| 五莲县| 工布江达县|