84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
如题:paramiko怎么判断远程目录是否存在?在调用exec_command函数的时候,怎么判断远程目录是否存在呢? 因为这里不能传if进去。
小伙看你根骨奇佳,潜力无限,来学PHP伐。
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")
You can use a simpler method, run some commands to detect the directory, such as ls, and then check the output!
Method 2:
Use sftp, do not use exec_command