jbardin / scp.py

scp module for paramiko

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does closing an SCPClient also close the underlying SSHClient? Should it?

SyntaxColoring opened this issue · comments

The readme gives this example for using an SCPClient with the with keyword:

ssh = SSHClient()
ssh.load_system_host_keys()
ssh.connect('example.com')

with SCPClient(ssh.get_transport()) as scp:
    scp.put('test.txt', 'test2.txt')
    scp.get('test2.txt')

It's not clear to me whether the implicit scp.close() at the end of the with block is also supposed to close() the underlying SSHClient. From the scp.py source, it doesn't look like it does; it looks like it just closes the underlying Channel.

Would this example be more correct?

with SSHClient() as ssh:
    ssh.load_system_host_keys()
    ssh.connect('example.com')

    with SCPClient(ssh.get_transport()) as scp:
        scp.put('test.txt', 'test2.txt')
        scp.get('test2.txt')

I suppose. Paramiko docs don't recommend using a with-block, so neither do we. It is a little weird to use one for SCPClient but not SSHClient, I admit.

Fixed by db5aad8