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 ...
随机推荐
- Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)【转】【修改】
一.基本概念: 1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成 ...
- 第9章 用内核对象进行线程同步(1)_事件对象(Event)
9.1 等待函数 (1)WaitForSingleObject(hObject,dwMilliseonds); ①dwMilliseconds为INFINITE时表示无限等待 ②dwMilliseco ...
- java 28 - 6 JDK7的新特性
JDK7的新特性: 二进制字面量 数字字面量可以出现下划线 switch 语句可以用字符串 泛型简化 异常的多个catch合并 try-with-resources 语句 二进制字面量 JDK7开始, ...
- Eclipse调整双击选取的字符颜色背景
Eclipse调整双击选取的字符颜色背景,如下图所示: 会有二点影响: 1. 编辑页的颜色 2. 右侧滚动条的小提示点的颜色.
- 学习cocos 空程序
今天开始学习cocos代码,首先研究源码中的空程序. 在这个程序中,在main函数中,创建了一个Application: int APIENTRY _tWinMain(HINSTANCE hInsta ...
- tomcat相关配置技巧梳理
tomcat常用架构:1)nginx+tomcat:即前端放一台nginx,然后通过nginx反向代理到tomcat端口(可参考:分享一例测试环境下nginx+tomcat的视频业务部署记录)2)to ...
- C语言操作文件
#include <stdio.h> struct stu{ ]; int num; int age; ]; }boya[],boyb[]; struct stu *pa,*pb; mai ...
- oracle 事务总结
用了这么长时间的oracle,该总结一下所得了 1,事务 事务用于保证数据的一致性, 它由一组相关的 dml语句组成, 该组的dml(数据操作语言,增删改,没有查询)语句要么全部成功,要么全部失败,比 ...
- 4809 江哥的dp题c
4809 江哥的dp题c 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 有两个数x,y,一开始x=1,y= ...
- mvc webapi 返回字符串自动加双引号
来自:http://www.cnblogs.com/David-Huang/p/4351023.html 返回字符串,突然碰到双引号号问题,幸亏有人解决了. 返回XMLDocument类型,默认会解析 ...