• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python 从远程服务器下载日志文件的程序

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

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python 日志,python 日志模块,python日志分析,python 打印日志,python 3日志等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

##################################################################
# 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'
</div>
运行:python getServerLog.py

</div>

您可能想查找下面的文章:

  • python日志记录模块实例及改进
  • 使用Python编写提取日志中的中文的脚本的方法
  • 使用Python编写提取日志中的中文的脚本的方法
  • python 从远程服务器下载日志文件的程序

相关文章

  • Ubuntu下创建虚拟独立的Python环境全过程
  • python列表操作实例
  • Python的Django框架中的URL配置与松耦合
  • Python实现读取目录所有文件的文件名并保存到txt文件代码
  • 使用PDB简单调试Python程序简明指南
  • Python入门及进阶笔记 Python 内置函数小结
  • Python对象转JSON字符串的方法
  • python友情链接检查方法
  • Python selenium 三种等待方式详解(必会)
  • 利用Python的Django框架中的ORM建立查询API

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • python从入门到精通(DAY 1)
    • bpython 功能强大的Python shell
    • pygame学习笔记(1):矩形、圆型画图实例
    • Django应用程序中如何发送电子邮件详解
    • 使用Python中的cookielib模拟登录网站
    • 在Python的web框架中中编写日志列表的教程
    • 动感网页相册 python编写简单文件夹内图片浏览工具
    • 在Python的列表中利用remove()方法删除元素的教程
    • 详解Python中的日志模块logging
    • 尝试用最短的Python代码来实现服务器和代理服务器

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有