Subject: sftp stat error - LIBSSH2_ERROR_SFTP_PROTOCOL


From: Phillip Wu <>
Date: Fri, 16 Apr 2010 15:03:49 +1000


I am getting sftp stat error -31.

I am using Solaris 10/GCC/libssh2 1.2.5.

This is a brief rundown of the code:
1. Create socket
2. Create ssh2 session
   session = libssh2_session_init();
   if (status=libssh2_session_startup(session, sock)) {
     fprintf(stderr, "Failure establishing SSH session - %d\n",status);
3. User authentication ... suceeds
   userauthlist = libssh2_userauth_list(session, username, strlen(username));
   if (strstr(userauthlist, "password") != NULL) {
     auth_pw |= 1;
   if (auth_pw & 1) {
      /* Authenticate via password */
      status=libssh2_userauth_password(session, username, password);
      if (status==0) {
          fprintf(stderr,"\tAuthentication by password succeeded.\n");
4. sftp stat
   char buf[]="/tmp/myfile";
   sftp_session = libssh2_sftp_init(session);

   if (!sftp_session) {
     fprintf(stderr, "Unable to init SFTP session - %d\n",status);

I'm getting error -31 (LIBSSH2_ERROR_SFTP_PROTOCOL) and on calling
libssh2_sftp_last_error(sftp_session, I get error 2.

I put sshd on the target machine into debug mode (sshd -d -d -d) and this is what I get:
debug3: fd 4 is not O_NONBLOCK
debug1: Server will not fork when running in debugging mode.
debug3: send_rexec_state: entering fd = 7 config len 321
debug3: ssh_msg_send: type 0
debug3: send_rexec_state: done
debug1: rexec start in 4 out 4 newsock 4 pipe -1 sock 7

Can you please suggest what is wrong? The same code worked OK under Redhat and
libssh2 version libssh2-1.1.

This message is intended for the addressee named and may contain confidential information. If you are not the intended recipient, please delete it and notify the sender. Views expressed in this message are those of the individual sender, and are not necessarily the views of the Land and Property Management Authority. This email message has been swept by MIMEsweeper for the presence of computer viruses.
Please consider the environment before printing this email.

Received on 2010-04-18