# -*- 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. Machine Learning Algorithms Study Notes(1)--Introduction

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 目 录 1    Introduction    1 1.1    ...

  2. Java的各种工具类

    下面是java的各种工具,包括获取时间和时间比较,检验集合和字符串是否为空和长度大小等等 1 import java.io.BufferedReader; import java.io.File; i ...

  3. NOIP2013pj小朋友的数字[DP 最大子段和]

    描述 有 n 个小朋友排成一列.每个小朋友手上都有一个数字,这个数字可正可负.规定每个小朋友的特征值等于排在他前面(包括他本人)的小朋友中连续若干个(最少有一个)小朋友手上的数字之和的最大值.作为这些 ...

  4. AC日记——独木桥 洛谷 p1007

    题目背景 战争已经进入到紧要时间.你是运输小队长,正在率领运输部队向前线运送物资.运输任务像做题一样的无聊.你希望找些刺激,于是命令你的士兵们到前方的一座独木桥上欣赏风景,而你留在桥下欣赏士兵们.士兵 ...

  5. Code! MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on (C#)

    http://www.asp.net/mvc/overview/security/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2- ...

  6. poj2580 Super Memmo

    Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participant i ...

  7. oracle存储过程中的if...elseif...else用法

    if ... then ...   elsif ... then ... else ...   end if; or     if ... then      ...   else ...   end ...

  8. performSelector的原理以及用法

    一.performSelector调用和直接调用区别下面两段代码都在主线程中运行,我们在看别人代码时会发现有时会直接调用,有时会利用performSelector调用,今天看到有人在问这个问题,我便做 ...

  9. 异常和IO

    异常 异常是指java程序运行时(非编译)所发生的非正常情况或错误. Java对异常进行了分类,不同类型的异常分别用不同的 Java 类表示,所有异常的根类为 java.lang.Throwable, ...

  10. swift——启动页国际化:一步一步动态加载启动页图片,启动的时候加载文字

    由于公司的需求,要求做一个国际化的启动页,因为app我也弄国际化了,就剩下启动页国际化未完成,百度了呵谷歌了好多答案都不尽如人意,最后也是看见同事完成,我也问了具体的做法,决定分享给需要的人,免得和我 ...