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.