python - paramiko怎么判断远程目录是否存在?
伊谢尔伦
伊谢尔伦 2017-04-18 09:04:49
0
1
2714

如题:paramiko怎么判断远程目录是否存在?
在调用exec_command函数的时候,怎么判断远程目录是否存在呢? 因为这里不能传if进去。

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
刘奇

You can use a simpler method, run some commands to detect the directory, such as ls, and then check the output!

stdin,stdout,stderr = client.exec_command('ls DIR')
if stdout.readline() != '':
    print("exist")
else:
    print("not exist")
    

Method 2:
Use sftp, do not use exec_command

sftp = client.open_sftp()
try:
    sftp.stat(path)
    print("exist")
except IOError:
    print("not exist")
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!