Operating System - HP-UX
1837655 Members
3030 Online
110117 Solutions
New Discussion

Re: C++ getting info via SSH2

 
SOLVED
Go to solution
Cecilia Sanchez
Occasional Contributor

C++ getting info via SSH2

Hello,

I have a C++ program making a connection to a unix server via SSH2 as follows:

system('ssh2 host -l uname -W Password.txt &)

A dos command window is launched and then I am stuck. I can go to the dos command window and do whatever. I need however to keep using the C++ program in order to get information (like get a file, chandge directories, or run a script). Do you know how can I achieve this? Are there any examples I can refer to out there?

Thank you!
5 REPLIES 5
James A. Donovan
Honored Contributor

Re: C++ getting info via SSH2

Does your ssh client allow you to pass the name of a command/script on the command line? Like so;

system('ssh2 host -l uname -W Password.txt myscript.sh &)

This would allow you to login and run what you need to and return the result to your calling program on stdout.
Remember, wherever you go, there you are...
Cecilia Sanchez
Occasional Contributor

Re: C++ getting info via SSH2

Hi Jim,

Yes it did! And I thought it would not take a script as a command, because I passed before the 'llogin' command and it would not take it:

system('ssh2 host -l uname -W Password.txt llogin&)

But, it did take a simple script I created:

system('ssh2 host -l uname -W Password.txt simple.csh &)

The script merely echoes a welcome message and displays a date. So, in the DOS command window I get back the welcome message and the date, but the connection does not remain open; that is, the prompt is at my local Widnows path, which I do not know if it is a problem or not.

What I need to do on the Unix is to read some files, manipulate them on Windows through the C++ program, and then put the modified files back.

Any ideas?

Thank you,
--Cecilia.


James A. Donovan
Honored Contributor
Solution

Re: C++ getting info via SSH2

My recommendation then would be that you use scp(2?) instead of ssh2 to copy the remote files to your local system. Then you could manipulate them as you wished, and replace the remote originals with your modified copies.
Remember, wherever you go, there you are...
Cecilia Sanchez
Occasional Contributor

Re: C++ getting info via SSH2

Thank you Jim. I have not noticed the scp2. Is this for secure copy? Are there any examples you can point me out to?

Thanks,
--Cecilia.
James A. Donovan
Honored Contributor

Re: C++ getting info via SSH2

Yes. SCP = secure copy.

You may want to take a look at this website for usage details.

http://www.openssh.org/manual.html
Remember, wherever you go, there you are...