无法使用Python Paramiko更改目录

2024-09-28 01:30:20 发布

您现在位置:Python中文网/ 问答频道 /正文

实际上,我需要用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

我需要检查上述文件是否存在于该特定文件夹中。为什么不能列出这些文件?任何帮助都将不胜感激


Tags: 文件clienthostparamikooutput错误stdoutchannel

热门问题