melsk
melsk

Reputation: 137

paramiko-python exec_command() cannot work on channel type tuple :(

Test Function

def GetTestFile():
    sshConn = paramiko.SSHClient()
    sshConn.load_system_host_keys()
    sshConn.connect(host, port, usrnm, pwrd)
    (connin, out, err) = sshObj.exec_command("cat test.txt")
    print out.readlines()
    lines = []
    for i in out.readlines():
        lines = lines.append(i)
        print lines
    print "Lines: ", lines
    sshConn.close()

As you know this performs a simple cat on the remote server. I want to transfer the contents of the out in to lines but when it outputs as [] (I checked the for loop doesn't seem to be executed for some odd reason)

Upvotes: 1

Views: 830

Answers (1)

TorelTwiddler
TorelTwiddler

Reputation: 6166

the list.append method does not return the list, it is an in-place append. You want

for i in out.readlines():
    lines.append(i)
    print lines

Upvotes: 1

Related Questions