Page MenuHomePhabricator

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


The API documentation for sftp_new() at says

Start a new sftp session.

The documentation for sftp_init() at 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 shows code

sftp = sftp_new(session);
if (sftp == NULL)
  fprintf(stderr, "Error allocating SFTP session: %s\n",
  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.Apr 29 2019, 10:10 AM