复制代码 代码如下:
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
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 周华健.2015-水浒三部曲原创音乐选辑【滚石】【FLAC分轨】
- 钟志刚《为爱而歌DSD》[WAV+CUE]
- 孙露《情人的眼泪》[低速原抓WAV+CUE]
- 【雨果唱片】刘明源《胡琴专辑》1993[WAV+CUE]
- 黄莺莺《25周年纪念金曲专辑》[WAV+CUE][1.1G]
- 刘德丽《刘德丽新曲+精选》2023[WAV+CUE][1G]
- 潘美辰《鹰与月》双语专辑[WAV+CUE][1G]
- 梁咏琪.2007-女色新曲+精选2CD【华纳】【WAV+CUE】
- 黎亚.2006-我不在巴黎【星外星】【FLAC分轨】
- 陈洁仪.1994-心痛【立得唱片】【WAV+CUE】
- 车载必备专用超级选曲《劲爆中文DJ》2CD[WAV+CUE]
- 群星《民歌流淌60年(黑胶CD)》2CD[WAV+分轨]
- 群星《美丽时光》紫银合金AQCD[WAV+CUE]
- 群星《12大巨星畅销精选集》[WAV分轨][1.1G]
- 华语排行冠军曲《百事音乐风云榜》[WAV+CUE][1G]