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 '192.168.2.177 (192.168.2.177)' 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
root_at_M320:~#
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;
switch(m_nUpgradeStage)
{
case RU_SSH_LOGON:
if (libssh2_session_handshake(m_pSSHSocket->m_pSession,
m_pSSHSocket->m_hSocket))
{
m_pProgressPg->m_wndProgressList.AddString(_T("Failed
to establish SSH session."));
return;
}
pchFingerprint =
libssh2_hostkey_hash(m_pSSHSocket->m_pSession, LIBSSH2_HOSTKEY_HASH_SHA1);
pchAuthList =
libssh2_userauth_list(m_pSSHSocket->m_pSession, "root", 8);
if(libssh2_userauth_password(m_pSSHSocket->m_pSession,
"root", "password"))
{
m_pProgressPg->m_wndProgressList.AddString(_T("Failed
to establish SSH session."));
return;
}
else
{
m_pProgressPg->m_wndProgressList.AddString(_T("Successfully
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);
if(m_bReadyToSendSSH)
{
m_pProgressPg->m_wndProgressList.AddString(_T("Preparing
to copy files."));
m_pSSHSocket->m_pChannel =
libssh2_scp_send(m_pSSHSocket->m_pSession, pchLocalFileName,
fileInfo.st_mode & 0777, (unsigned long) fileInfo.st_size);
if(!m_pSSHSocket->m_pChannel)
{
char* pchErrMsg;
int nErrLen;
int nErr =
libssh2_session_last_error(m_pSSHSocket->m_pSession, &pchErrMsg, &nErrLen, 0);
}
}
break;
}
}
Thanks in advance for any and all feedback!
Dave.
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2013-02-15