[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Simple non-interactive shell
[Thread Prev] | [Thread Next]
- Subject: Simple non-interactive shell
- From: Aloys Delobel <aloysdelobel@xxxxxxxxxxxxxx>
- Reply-to: Aloys Delobel <aloysdelobel@xxxxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Mon, 25 Nov 2019 11:04:37 +0000
- To: "libssh@xxxxxxxxxx" <libssh@xxxxxxxxxx>
Hi everybody, I'm trying to set a simple non-interactive shell, between my program (which sends commands to the remote shell) and the server. Here's my program : int pass_instruction(ssh_channel channel, int commandcode, std::string filename){ std::string command; if (commandcode == MV_FILE){ command = "cp repository/" + filename + " onthego/" ; rc = ssh_channel_write(channel, command.c_str(), sizeof(command)); if (rc != sizeof(command)){ std::cout << rc; return rc; } } return SSH_OK; } int main () { int rc(0); ssh_session session; ssh_channel channel; // skip the setting of session channel = ssh_channel_new(session); if (channel == NULL) return SSH_ERROR; rc = ssh_channel_open_session(channel); if (rc != SSH_OK){ ssh_channel_free(channel); return rc; } rc = ssh_channel_request_shell(channel); if (rc != SSH_OK){ ssh_channel_free(channel); return rc; } rc = pass_instruction(channel, MV_FILE, "example.txt"); if (rc != SSH_OK) { return -1; } rc = pass_instruction(channel, MV_FILE, "example2.txt") ; if (rc != SSH_OK) { return -1; } // Delete / close / ... channel then session return 0; } And the problem is : the line "pass_instruction(channel, MV_FILE, "example.txt");" works and copy the file, then the "pass_instruction(channel, MV_FILE, "example2.txt") ;" works according to the program, but the file is not copied. I don't understand why... Thanks for helping ! Aloys D.
Re: Simple non-interactive shell | g4-lisz@xxxxxxxxxxxx |
Re: Simple non-interactive shell | Andreas Schneider <asn@xxxxxxxxxxxxxx> |