title: SFTP libssh failure
body: <p>I am using the libssh library and trying to create a new SFTP session. I keep getting an error message of </p>
  
  <blockquote>
    <p>ssh_packet_unimplemented:  Received SSH_MSG_UNIMPLEMENTED (sequence number 3)</p>
  </blockquote>
  
  <p>I checked the syslog of the remote server and found the error</p>
  
  <blockquote>
    <p>dispatch_protocol_error: type 90 seq 3 [preauth]</p>
  </blockquote>
  
  <p>For some reason I get this error when trying to use the following (taken from the <a href="http://api.libssh.org/master/libssh_tutor_sftp.html" rel="nofollow noreferrer">libssh doc</a>)</p>
  
  <pre><code>int sftp_helloworld(ssh_session session) {
    sftp_session sftp;
    int rc;
    sftp = sftp_new(session); // Freezes at this part
    if (sftp == NULL) {
      fprintf(stderr, "Error allocating SFTP session: %s\n", ssh_get_error(session));
      return SSH_ERROR;
    }
    rc = sftp_init(sftp);
    if (rc != SSH_OK) {
      fprintf(stderr, "Error initializing SFTP session: %s.\n", sftp_get_error(sftp));
      sftp_free(sftp);
      return rc;
    }
    sftp_free(sftp);
    return SSH_OK;
  }
  </code></pre>
  
  <p>The only thing that is working is the actual ssh connection. The same error occurs whether I'm using SCP, SFTP or when opening a remote shell.</p>
  
  <p>I've researched a lot regarding my issue, but couldn't find any remedies. Any help would be great.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>On the Amazon EC2 server I looked through <code>/var/log/auth.log</code> and found this:</p>
  
  <blockquote>
    <p>sshd[24860]: Accepted publickey for ubuntu </p>
    
    <p>sshd[24860]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0)</p>
    
    <p>sshd[24930]: dispatch_protocol_error: type 90 seq 3 [preauth]</p>
  </blockquote>
  
  <p>In the libssh code I set the <code>SSH_OPTIONS_LOG_VERBOSITY</code> to <code>SSH_LOG_PACKET</code>, everything runs smoothly, but when it gets to the <code>sftp_new()</code> I recieve this error and it freezes at the <code>SSH_MSG_UNIMPLEMENTED</code> message,</p>
  
  <blockquote>
    <p>channel_open:  Creating a channel 43 with 64000 window and 32768 max
    packet</p>
    
    <p>packet_send2:  packet: wrote [len=44,padding=19,comp=24,payload=24]</p>
    
    <p>channel_open:  Sent a SSH_MSG_CHANNEL_OPEN type session for channel 43</p>
    
    <p>ssh_socket_unbuffered_write:  Enabling POLLOUT for socket</p>
    
    <p>ssh_packet_socket_callback:  packet: read type 3
    [len=12,padding=6,comp=5,payload=5]</p>
    
    <p>ssh_packet_process:  Dispatching handler for packet type 3</p>
    
    <p>ssh_packet_unimplemented:  Received SSH_MSG_UNIMPLEMENTED (sequence
    number 3)</p>
  </blockquote>
  
  <p><strong>EDIT2:</strong></p>
  
  <p>I used the following code to connect to the server,</p>
  
  <pre><code>ssh_key pKey;
  int rc = ssh_pki_import_privkey_file(PC_PRIVATE_KEY_FILE, NULL, NULL, NULL, &amp;pKey);
  
  ssh_session my_ssh_session = ssh_new();
  
  ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, PC_HOST);
  ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, PC_USER);
  ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &amp;PC_PORT);
  ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &amp;PC_VERBOSITY);
  
  rc = ssh_connect(my_ssh_session);
  </code></pre>
  
  <p>I was confused by the <a href="http://api.libssh.org/master/libssh_tutorial.html" rel="nofollow noreferrer">tutorial</a>. I might have not wrote the code to connect to the server properly.</p>