Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
foxx opened this issue May 31, 2013 · 3 comments
Open

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

foxx opened this issue May 31, 2013 · 3 comments

Comments

@foxx
Copy link

foxx commented May 31, 2013

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

@foxx
Copy link
Author

foxx commented May 31, 2013

If I use the following;

    for x in range(1,21000):
        chan.write(str(x)+"\r\n")

I then end up with;

> tail /tmp/lol -n 5
20308
20309
20310
20311

So it seems to be dropping the last chunks of data.. if I increase 21000 to 22000, it will still continue to increase but will drop out at 21311 instead.

If I change this to 5, nothing appears in the file at all;


    for x in range(1,5):
        chan.write(str(x)+"\r\n")

 > ls -lah /tmp/lol
-rwx------ 1 pippaprod pippaprod 0 May 31 15:15 /tmp/lol

@foxx
Copy link
Author

foxx commented May 31, 2013

Also;

libssh2 is: 1.2.6-1
Python 2.6.6

Hopefully this can be fixed!

Thanks

@Jhoanor
Copy link

Jhoanor commented Jul 3, 2013

I have nearly the same issue on OpenBSD with python 2.7 and libssh2-1.4.3
Though my 238Mb testfile is send and received correctly.
I also get an error code:
_libssh2.Error: Unable to close the channel (error -34).

I used pylibssh2-1.0.3
But, if I install the old version pylibssh2-1.0.0, I do not get an error. That version works fine!!
(1.0.1 gives an error, 1.0.2 I didn't try)

After some searching it turns out there is an error in channel.c line 46:
it should be:
if (rc && rc != LIBSSH2_ERROR_EAGAIN)
That does work. Otherwise, after a succesfull close, it wil try to close again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants