www.libssh2.org | Daily snapshots | Mailing list archive | Docs | Examples | github

Archive Index This month's Index

Subject: SCP failing with "failed to send file"

SCP failing with "failed to send file"

From: Dave Colter <dave_at_knudsenengineering.com>
Date: Fri, 15 Feb 2013 09:30:04 -0500

I'm writing a Windows C++ utility to update files on a remote
terminal, a Debian box. The steps of the process are:

1. Establish a Telnet connection with the remote
2. Send a ps -f command to get a list of running procs
3. Kill the process we want to update
4. Start SSH on the remote
5. Establish an SSH connection with the remote
6. SCP the new files to the remote

Everything works smoothly up to step 6, where libssh2_scp_send()
fails. libssh2_session_last_error() returns "failed to send file".
Tracing into the scp_send() function, the _libssh2_channel_write()
function succeeds. A subsequent call to _libssh2_channel_read()
returns one byte: 0x01. Another call to _libssh2_channel_read()
returns an error message: "scp: <filepath>: No space left on
device\n". I don't believe space is the problem (the file I'm
attempting to upload is 19,821 bytes):

/ # df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/ram0 1507 1180 327 78% /
none 63728 0 63728 0% /dev
none 63728 0 63728 0% /dev/shm
/dev/mtdblock3 515584 461456 54128 90% /mnt/root

Trying to scp the files manually using PuTTY, I run into a different
problem. Using a Telnet window, I do steps 1-4. Then I open an SSH
window, logon and attempt the scp. Here's the output:

root_at_M320:~# scp new_file_at_192.168.2.177:/sbin
Could not create directory '/root/.ssh'.
The authenticity of host ' (' can't be established.
RSA key fingerprint is 0b:1e:2f:0b:13:e5:d9:2e:cc:27:f0:73:7b:2a:50:20.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/root/.ssh/known_hosts).
root_at_192.168.2.177's password:
new_file: No such file or directory

In the end, it can't find the file I want to upload (I'd like to know
why, but that's a secondary problem). Does any of the preceding
output give some clue as to why my program is not working? Here is a
piece of my program code:

     const char* pchFingerprint;
     char* pchAuthList;
         case RU_SSH_LOGON:
             if (libssh2_session_handshake(m_pSSHSocket->m_pSession,
to establish SSH session."));

             pchFingerprint =
libssh2_hostkey_hash(m_pSSHSocket->m_pSession, LIBSSH2_HOSTKEY_HASH_SHA1);
             pchAuthList =
libssh2_userauth_list(m_pSSHSocket->m_pSession, "root", 8);

"root", "password"))
to establish SSH session."));
logged in to remote via SSH."));
                 m_nUpgradeStage = RU_SSH_COPY_FILES;

             struct _stat64i32 fileInfo;
             const char* pchLocalFileName = "..\\debug\\files\\new_file";
             ::_stat(pchLocalFileName, &fileInfo);

to copy files."));
                 m_pSSHSocket->m_pChannel =
libssh2_scp_send(m_pSSHSocket->m_pSession, pchLocalFileName,
fileInfo.st_mode & 0777, (unsigned long) fileInfo.st_size);
                     char* pchErrMsg;
                     int nErrLen;
                     int nErr =
libssh2_session_last_error(m_pSSHSocket->m_pSession, &pchErrMsg, &nErrLen, 0);


Thanks in advance for any and all feedback!


libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2013-02-15

the libssh2 team