python 从远程服务器下载日志文件的程序

所属分类: 脚本专栏 / python 阅读数: 2077
收藏 0 赞 0 分享

复制代码 代码如下:

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

更多精彩内容其他人还在看

keras-siamese用自己的数据集实现详解

这篇文章主要介绍了keras-siamese用自己的数据集实现详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Python xlrd模块导入过程及常用操作

这篇文章主要介绍了Python xlrd模块导入过程及常用操作,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
收藏 0 赞 0 分享

keras打印loss对权重的导数方式

这篇文章主要介绍了keras打印loss对权重的导数方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Keras 使用 Lambda层详解

这篇文章主要介绍了Keras 使用 Lambda层详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

浅谈Python中的字符串

这篇文章主要介绍了Python中的字符串相关知识,文中讲解的非常细致,代码帮助大家更好的理解,感兴趣的朋友可以参考下
收藏 0 赞 0 分享

PySide2出现“ImportError: DLL load failed: 找不到指定的模块”的问题及解决方法

这篇文章主要介绍了PySide2出现“ImportError: DLL load failed: 找不到指定的模块”的问题及解决方法,本文通过实例代码给大家介绍的非常详细,需要的朋友可以参考下
收藏 0 赞 0 分享

Tensorflow中k.gradients()和tf.stop_gradient()用法说明

这篇文章主要介绍了Tensorflow中k.gradients()和tf.stop_gradient()用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

matplotlib 生成的图像中无法显示中文字符的解决方法

这篇文章主要介绍了matplotlib 生成的图像中无法显示中文字符的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

keras 使用Lambda 快速新建层 添加多个参数操作

这篇文章主要介绍了keras 使用Lambda 快速新建层 添加多个参数操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

JAVA及PYTHON质数计算代码对比解析

这篇文章主要介绍了JAVA及PYTHON质数计算代码对比,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多