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

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

伊谢尔伦
伊谢尔伦

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

répondre à tous(1)
刘奇

可以使用笨一点方法,运行一些对目录检测的命令,如ls,然后去检测输出!

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

方法二:
使用sftp, 不使用exec_command

sftp = client.open_sftp()
try:
    sftp.stat(path)
    print("exist")
except IOError:
    print("not exist")
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!