Skip to content

_libssh2.Error: Unable to close the channel. #20

@foxx

Description

@foxx
Traceback (most recent call last):
  File "test.py", line 94, in <module>
    libssh2_upload()
  File "test.py", line 92, in libssh2_upload
    chan.close()
  File "/usr/local/lib/python2.6/dist-packages/pylibssh2-1.0.1-py2.6-linux-x86_64.egg/libssh2/channel.py", line 53, in close
    return self._channel.close()
_libssh2.Error: Unable to close the channel.

Code being used;

def libssh2_upload():
    import libssh2
    import tempfile
    import os
    import socket

    host = "xxx"
    user = "xxx"
    file_to_send = "/tmp/lol"

    fd, fpath = tempfile.mkstemp()
    fh = os.fdopen(fd, 'w')
    fh.write(key)
    fh.close()

    fd2, fpath2 = tempfile.mkstemp()
    fh2 = os.fdopen(fd2, 'w')
    fh2.write(pubkey)
    fh2.close()

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((host, 22))
    sock.setblocking(1)

    session = libssh2.Session()
    session.set_banner()
    session.startup(sock)
    session.userauth_publickey_fromfile(user, fpath2, fpath, "")

    fsize = os.path.getsize(file_to_send)
    chan = session.scp_send(file_to_send, 0700, fsize)

    sf = open(file_to_send, 'rb')
    while True:
        c = sf.read(512)
        if not c:
            break
        chan.write(c)
    chan.close()

libssh2_upload()

Also, the file is corrupt on the other side (md5 mismatch) and the size is very different.

Any ideas?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions