Page MenuHomePhabricator

Difference between sftp_new() and sftp_init() is not clear
Open, Needs TriagePublic

Description

The API documentation for sftp_new() at http://api.libssh.org/master/group__libssh__sftp.html#gae84eeb5a1af9d49db10f17a060151e97 says

Start a new sftp session.

The documentation for sftp_init() at http://api.libssh.org/master/group__libssh__sftp.html#gab8ec37b2cb85c9bb47341683f43f0841 says

Initialize the sftp session with the server.

So the documentation suggests that communication with the server only happens at sftp_init() when in fact, already sftp_new() allocates the channel and communicates with the server and when the sftp subsystem is not enabled in the sshd server, it will fail with error message

Channel request subsystem failed

Also the documentation at http://api.libssh.org/master/libssh_tutor_sftp.html shows code

sftp = sftp_new(session);
if (sftp == NULL)
{
  fprintf(stderr, "Error allocating SFTP session: %s\n",
          ssh_get_error(session));
  return SSH_ERROR;
}

where the error message Error allocating suggests that sftp_new() is merely about allocating the memory for the structure locally, like ssh_new() does.

What is the difference between the two? Why are there two separate calls at all? Shouldn't sftp_new() just allocate and only sftp_init() do any communication on the network?

Event Timeline

adelton created this task.Mar 14 2019, 2:15 PM

The behaviour was observed on Fedora 29 with libssh-0.8.7-1.fc29.x86_64.

asn added a project: Restricted Project.Mon, Apr 29, 10:10 AM