Вопрос

I'm using the most recent Git tree of libssh2 to perform some SFTP work. I'm using the non-blocking interface.

I'm successful in establishing a connection to the SFTP server, logging in, and transferring files.

However, I'm encountering a problem where the call to libssh2_sftp_write(sftp_handle, ptr, nread) plain hangs. This always happens after 237115172 bytes of data are transferred.
While the payload is smaller than this number, things proceed just fine.

I'm transferring multiple files. I'm using a single SSH session (and a single socket) for the entire transaction. Can anyone suggest a direction for solving this problem? The magic number 237115172 is a hint, but it doesn't make any sense to me just yet. What could I be doing wrong?

This is the code, straight out of the libssh2 examples:

do 
{
    nread = fread(m_buffer, 1, sizeof(m_buffer), local);
    //
    // EOF
    //
    if (nread <= 0) 
        break;
    ptr = m_buffer;
    total += nread;
    do 
    {
        //
        // FIXME: this hangs sometimes... why?!
        //

        /* write data in a loop until we block */
        while 
        (
            (rc = libssh2_sftp_write(sftp_handle, ptr, nread)) 
            == 
            LIBSSH2_ERROR_EAGAIN
        ) 
        {
            if (m_aborted)
                goto cleanup;
            waitsocket(m_sock, m_session);
        }
        if (rc < 0)
            break;
        ptr += rc;
        nread -= rc;
        m_uploadedBytes += rc;
        emit totalUploadChanged(100*(float)m_uploadedBytes/m_totalBytes);
    } 
    while (nread);
} 
while (rc > 0);

I can post the full source, but it's quite long, and since it's part of a QT app it would take a bit of effort to rip out.

Это было полезно?

Решение

I noticed that I had two versions of libssh2 installed: 1.2.2. in /usr and 1.3.0 (from the git repository) in /usr/local. I didn't have any attachment to a particular version, so I removed the more recent one (the older one was a dependency for other software on my machine).

I had to make two or three small changes to adapt to the older interface, but at least the problem described in the original question went away.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top