[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Simple non-interactive shell
[Thread Prev] | [Thread Next]
- Subject: Re: Simple non-interactive shell
- From: Andreas Schneider <asn@xxxxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Thu, 28 Nov 2019 11:36:32 +0100
- To: libssh@xxxxxxxxxx, Aloys Delobel <aloysdelobel@xxxxxxxxxxxxxx>
On Monday, 25 November 2019 12:04:37 CET Aloys Delobel wrote: > 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... This only write to the channel, you also need to read and check that the command has been successfully executed before sending the next. andreas -- Andreas Schneider asn@xxxxxxxxxxxxxx GPG-ID: 8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D
Simple non-interactive shell | Aloys Delobel <aloysdelobel@xxxxxxxxxxxxxx> |