# -*- 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的更多相关文章

  1. EasyHook Creating a remote file monitor

    In this tutorial we will create a remote file monitor using EasyHook. We will cover how to: 使用EasyHo ...

  2. 远程文件同步详解(Remote File Sync)

    1. 远程文件同步的常见方式: 1.cron + rsync 优点: 简单 缺点:定时执行,实时性比较差:另外,rsync同步数据时,需要扫描所有文件后进行比对,进行差量传输.如果文件数量达到了百万甚 ...

  3. 实战远程文件同步(Remote File Sync)

    1. 远程文件同步的常见方式: 1.cron + rsync 优点: 简单 缺点:定时执行,实时性比较差:另外,rsync同步数据时,需要扫描所有文件后进行比对,进行差量传输.如果文件数量达到了百万甚 ...

  4. [PHP学习教程 - 文件]002.判断远程文件是否存在(Remote File Exists)

    引言:项目过程当中碰到了类似流程这样的需求,对服务器上的文件进行依次操作,如:检查文件格式->检查文件是否有更新->处理更新->同步其他服务器等等 如果需求的操作是依赖于远程文件是否 ...

  5. 用 shell 脚本做命令行工具扩展

    问题的提出 公司开发机与远程服务器之间有严格的隔离策略,不能直接使用 ssh 登录,而必需通过跳板机.这样一来,本地与服务器之间的一些文件传输变得非常不便.经过咨询,运维教了我一招: $ nc -l ...

  6. 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 ...

  7. Sensitive directory/file Integrity Monitoring and Checking

    catalogue . OSSEC . HashSentry: Host-Based IDS in Python . Afick . 检测流程 1. OSSEC OSSEC is an Open So ...

  8. Design and Implementation of the Sun Network File System

    Introduction The network file system(NFS) is a client/service application that provides shared file ...

  9. C#中File类的文件操作方法详解

    File类,是一个静态类,主要是来提供一些函数库用的.静态实用类,提供了很多静态的方法,支持对文件的基本操作,包括创建,拷贝,移动,删除和打开一个文件.File类方法的参量很多时候都是路径path.F ...

随机推荐

  1. 单机搭建Android开发环境(二)

    前文介绍了如何优化SSD和内存,以发挥开发主机的最佳性能,同时提到在SSD上创建虚拟机.为什么不装双系统呢?双系统性能应该会更好!采用Windows+虚拟机的方式,主要是考虑到安卓开发和日常办公两方面 ...

  2. NOIP2002pj产生数[floyd 高精度]

    背景 给出一个整数 n(n<10^30) 和 k 个变换规则(k<=15). 规则:一位数可变换成另一个一位数:规则的右部不能为零. 例如:n=234.有规则(k=2):2-> 53 ...

  3. Thread对象的yield(),wait(),notify(),notifyall()

    Thread类中的主要方法: join()方法:让一个线程强制运行,线程强制运行期间,其他线程无法运行,必须等到此线程完成之后才可以继续执行. setDaemon():设置线程为后台线程,这样即使Ja ...

  4. [No000040]取得一个文本文件的编码方式

    using System; using System.IO; using System.Text; /// <summary> /// 用于取得一个文本文件的编码方式(Encoding). ...

  5. Canon

    .打开压缩包发现2个文件,1个是加密的zip.zip,另一个是music.mp3.猜测zip.zip的解压密码隐藏在music.mp3里 .用MP3Stego解密music.mp3,密码就是标题的Ca ...

  6. oracle的substr函数的用法

    oracle的substr函数的用法 取得字符串中指定起始位置和长度的字符串   substr( string, start_position, [ length ] ) 如:     substr( ...

  7. web cache server方案比较:varnish、squid、nginx

    linux运维中,web cache server方案的部署是一个很重要的环节,选择也有很多种比如:varnish.squid.nginx.下面就对当下常用的这几个web cache server做一 ...

  8. ES6 WeakSet数据结构 与Set十分相似

    它与Set十分相似,对象的值也不能是重复的,与Set不同点: .WeakSet成员只能够是对象. .作为WeakSet成员的对象都是弱引用,即垃圾回收机制不考虑WeakSet对该对象的引用,也就是说, ...

  9. Post model至Web Api创建或是保存数据

    前一篇<Post model至Web Api>http://www.cnblogs.com/insus/p/4343538.html中,使用Post来从Web Api获取数据.由于Post ...

  10. NET代码重构

    记一次.NET代码重构   好久没写代码了,终于好不容易接到了开发任务,一看时间还挺充足的,我就慢慢整吧,若是遇上赶进度,基本上直接是功能优先,完全不考虑设计.你可以认为我完全没有追求,当身后有鞭子使 ...