judge remote file exist
# -*- coding:utf-8 -*-
import paramiko,os,sys,time
print '''
*****判断远端服务器上的某个文件是否存在*****
'''
ip = raw_input("请输入目标主机的IP:》》")
password = raw_input("请输入目标主机的密码:》》")
#remote_file_path =raw_input("请输入文件所在目录的绝对路径:》》")
#remote_file_name = raw_input("请输入要查询的文件名称:》》")
print '''
*****正在连接远程主机,请稍等******
'''
time.sleep(1)
while True:
remote_file_path =raw_input("请输入文件所在目录的绝对路径:》》 按q退出程序")
if remote_file_path == 'q':
print "感谢使用,再见"
exit()
remote_file_name = raw_input("请输入要查询的文件名称:》》")
print '''
******正在判断,请稍等******
'''
'''def file_exist(ip,port,user,password):
result=""
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,port,user,password)
stdin, stdout, stderr = ssh.exec_command('ls %s'%remote_file_path )
list_str = stdout.read().split()
#print list_str
except:
print "未知错误"
return result b = file_exist(ip,22,'root',password)
print b
#if remote_file_name in file_exist(ip,22,'root',password):
# print "%s 文件存在"%remote_file_name
#else:
# print "%s 不存在"%remote_file_name'''
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,22,'root',password,timeout=3)
except:
print "未知错误"
stdin,stdout,stderr = ssh.exec_command('ls %s'%remote_file_path)
dir_list = stdout.read().split()
if remote_file_name in dir_list:
print "%s 存在"%remote_file_name
else:
print "%s 不存在"%remote_file_name
judge remote file exist的更多相关文章
- EasyHook Creating a remote file monitor
In this tutorial we will create a remote file monitor using EasyHook. We will cover how to: 使用EasyHo ...
- 远程文件同步详解(Remote File Sync)
1. 远程文件同步的常见方式: 1.cron + rsync 优点: 简单 缺点:定时执行,实时性比较差:另外,rsync同步数据时,需要扫描所有文件后进行比对,进行差量传输.如果文件数量达到了百万甚 ...
- 实战远程文件同步(Remote File Sync)
1. 远程文件同步的常见方式: 1.cron + rsync 优点: 简单 缺点:定时执行,实时性比较差:另外,rsync同步数据时,需要扫描所有文件后进行比对,进行差量传输.如果文件数量达到了百万甚 ...
- [PHP学习教程 - 文件]002.判断远程文件是否存在(Remote File Exists)
引言:项目过程当中碰到了类似流程这样的需求,对服务器上的文件进行依次操作,如:检查文件格式->检查文件是否有更新->处理更新->同步其他服务器等等 如果需求的操作是依赖于远程文件是否 ...
- 用 shell 脚本做命令行工具扩展
问题的提出 公司开发机与远程服务器之间有严格的隔离策略,不能直接使用 ssh 登录,而必需通过跳板机.这样一来,本地与服务器之间的一些文件传输变得非常不便.经过咨询,运维教了我一招: $ nc -l ...
- 5105 pa3 Distributed File System based on Quorum Protocol
1 Design document 1.1 System overview We implemented a distributed file system using a quorum based ...
- Sensitive directory/file Integrity Monitoring and Checking
catalogue . OSSEC . HashSentry: Host-Based IDS in Python . Afick . 检测流程 1. OSSEC OSSEC is an Open So ...
- Design and Implementation of the Sun Network File System
Introduction The network file system(NFS) is a client/service application that provides shared file ...
- C#中File类的文件操作方法详解
File类,是一个静态类,主要是来提供一些函数库用的.静态实用类,提供了很多静态的方法,支持对文件的基本操作,包括创建,拷贝,移动,删除和打开一个文件.File类方法的参量很多时候都是路径path.F ...
随机推荐
- [原创]用C++类实现单向链表的增删查和反转操作
数据结构这东西,理解起来不算难,但是实现难度就不小了,虽然思路很清晰,但不知道从何下手还有语言的细节问题一直是阻碍初学者的主要障碍(比如我).今天用了一下午时间终于独立完成了链表操作. 找网上的代码, ...
- DPM(voc-release5) Matlab模型文件 Mat转XML
(转载请注明作者和出处 楼燚(yì)航的blog :http://www.cnblogs.com/louyihang loves baiyan/ 未经允许请勿用于商业用途) 由于目前DPM模型训练的代 ...
- hdu 5898 odd-even number 数位DP
传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...
- Appium学习实践(一)简易运行Appium
环境: Appium 1.4.13 OS X 10.10.5 真机已安装app,或者未安装,通过ipa文件来安装,并启动Appium Inspector 点击Appium中的放大镜后,自动运行App ...
- 洛谷U4807抽水机[最小生成树]
题目背景 kkk被Farmer John和他的奶牛贝茜虐的很惨,然后她也想体验下一个Farmer的生活.但她又懒得种地,就选择养鱼. 题目描述 这些鱼都是热带鱼(废话),很娇贵(比kkk娇贵),要经常 ...
- 前端面试——css篇
css盒子模型 在W3C模型中: 总宽度 = margin-left + border-left + padding-left + width + padding-right + border-rig ...
- React问题总结与归纳
欢迎大家指导与讨论 : ) [持续更新]本文主要记录笔者在学习中遇到的问题,并作出相应总结.有错误的地方希望各位能够指出. 一.在es6中getInitialState( 摘要: construct ...
- Android项目,从web上取下汉字,中文部分乱码
Android项目,从web上取下汉字,中文部分乱码. 常见问题,搜索一下,网上有很多办法解决.如果还没有试过这个办法,可以尝试一下. BufferedReader in = new Buffered ...
- Windows 8.1 新增控件之 MenuFlyout
开始这篇讲解前,我们先来温习一下Flyout 的内容,当触发应用中某个Button 时会有Flyout 出现提示用户该操作接下来将会发生什么.Flyout 简单来说就是一个轻量级信息提示需要用户确认或 ...
- Theano2.1.8-基础知识之装载和保存
来自:http://deeplearning.net/software/theano/tutorial/loading_and_saving.html loading and saving Pytho ...