Skip to content

Documentation suggesting incorrect flags for sftp.open() #13

Closed
@gvialetto

Description

@gvialetto

Steps to reproduce:

Simply use the code in the README file to read a file from SFTP:

sftp = session.sftp_init()
with sftp.open(<remote file to read>, 0, 0) as remote_fh, \
        open(<file to write>, 'wb') as local_fh:
    for size, data in remote_fh:
        local_fh.write(data)

Expected behaviour:

Data is copied from the remote file to the local file.

Actual behaviour:

No data is ever written to <file to write>. The size parameter is set by libssh2 to LIBSSH2_ERROR_SFTP_PROTOCOL (-31) and the calling sftp.last_error() will report LIBSSH2_FX_FAILURE (4). remote_fh.fstat() will succeed without issues (reporting correct data).

Additional info:

Version ssh2-python 0.6.0 with bundled libssh2.

This seems to happen because (at least up to libssh2 1.8.0) 0 and LIBSSH2_FXF_READ are not synonyms, like it is (in my understanding) incorrectly suggested in the documentation and the examples (sftp_read.py, for example). This may be tested using libssh2 directly by changing line 251 of the sftp.c example from:

libssh2_sftp_open(sftp_session, sftppath, LIBSSH2_FXF_READ, 0);

to

libssh2_sftp_open(sftp_session, sftppath, 0, 0);

This will make libssh2_sftp_read() fail in in the same way described in the actual behaviour.

I should be able to send a pull request to fix the documentation and examples if needed (and my understanding of the issue is correct).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions