实际上,我需要用Paramiko检查一个文件。我得到以下错误。如果你们中有人能解决这个问题,这将是很有帮助的
import paramiko
try:
host = '23.120.7.00'
username = 'UNAME1'
password = 'UNAME12'
file_to_check = '\\\\ipconnect\\ABCS\\IPXADEP\\file1.dta'
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host,username=username, password=password)
channel = client.get_transport().open_session()
channel.exec_command('cd \\\\ipconnect\\ABCS\\IPXADEP')
stdin, stdout, stderr = channel.exec_command('ls')
stdout = channel.makefile().read()
output = stdout.decode('utf-8').split('\n')[:-1]
print(output)
client.close()
except Exception as e:
print(str(e))
我得到以下错误:
cannot unpack non-iterable NoneType object
我需要检查上述文件是否存在于该特定文件夹中。为什么不能列出这些文件?任何帮助都将不胜感激
首先,您的代码不能以这种方式工作
见Execute multiple commands in Paramiko so that commands are affected by their predecessors
但要操作文件,无论如何都不应该使用shell命令。使用标准SSH API操作文件SFTP:
相关问题 更多 >
编程相关推荐