Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How do to SCP from within my C++ program?

Reply
Thread Tools

How do to SCP from within my C++ program?

 
 
Saqib Ali
Guest
Posts: n/a
 
      02-10-2011

Hi.

I'm writing C++ code that is running on a Solaris system.

From within my C++ program, I need to copy files from one machine to
another using SFTP or SCP. I would like to learn how to do so
programatically.

There seems to be no standard C++ library (such as iostream, strings,
etc) that would do this. I don't know why. Can anyone explain this to
me? Without such a library, it seems my only option would be to run an
operating system call. However if I did so, a user would need to type
in a password during execution. That seems sub-optimal.

I wish there was a function that looked like this:

scp(sourceFile, targetMachine, targetUser, targetPassword, targetFile)

What do other people do in this situation?

Thanks much.
- Saqib
 
Reply With Quote
 
 
 
 
Jasen Betts
Guest
Posts: n/a
 
      02-10-2011
On 2011-02-10, Saqib Ali <(E-Mail Removed)> wrote:
>
> Hi.
>
> I'm writing C++ code that is running on a Solaris system.


> From within my C++ program, I need to copy files from one machine to
> another using SFTP or SCP. I would like to learn how to do so
> programatically.


every operating system is different, so there's no standard library
for spawing external programs.

> There seems to be no standard C++ library (such as iostream, strings,
> etc) that would do this. I don't know why. Can anyone explain this to
> me?


ms windows doesn't have naything remotely like fork() or exec() or even
a real argv[]. it's basically too hard to do that sort of thing in
a standardisable way.

> Without such a library, it seems my only option would be to run an
> operating system call. However if I did so, a user would need to type
> in a password during execution. That seems sub-optimal.


ypu can use a public key instead of password with both scp and sftp (which
are both essentially ssh rebranded)

> I wish there was a function that looked like this:
>
> scp(sourceFile, targetMachine, targetUser, targetPassword, targetFile)
>
> What do other people do in this situation?


Since this is a linux newsgroup, atleast for me....

I use GVFS every day to edit remote files with a local editor
it works fairly well (editor tends to crash occasionally in the
directory browser, not sure why)

AIUI programatically it's just ordinary local file operations on the correct
GVFS path. gnome somehow fiugures out when it needs to ask me for a password
or for access to the keychain.

--
⚂⚃ 100% natural
 
Reply With Quote
 
 
 
 
Paul
Guest
Posts: n/a
 
      02-10-2011

"Jasen Betts" <(E-Mail Removed)> wrote in message
news:ij0io3$nqb$(E-Mail Removed)...
> On 2011-02-10, Saqib Ali <(E-Mail Removed)> wrote:
>>
>> Hi.
>>
>> I'm writing C++ code that is running on a Solaris system.

>
>> From within my C++ program, I need to copy files from one machine to
>> another using SFTP or SCP. I would like to learn how to do so
>> programatically.

>
> every operating system is different, so there's no standard library
> for spawing external programs.
>
>> There seems to be no standard C++ library (such as iostream, strings,
>> etc) that would do this. I don't know why. Can anyone explain this to
>> me?

>
> ms windows doesn't have naything remotely like fork() or exec() or even
> a real argv[]. it's basically too hard to do that sort of thing in
> a standardisable way.
>

CreateProcess()



 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      02-10-2011
On Feb 10, 12:37 pm, "Paul" <(E-Mail Removed)> wrote:
> "Jasen Betts" <(E-Mail Removed)> wrote in message


> news:ij0io3$nqb$(E-Mail Removed)...


> > On 2011-02-10, Saqib Ali <(E-Mail Removed)> wrote:


> >> I'm writing C++ code that is running on a Solaris system.


> >> From within my C++ program, I need to copy files from one machine to
> >> another using SFTP or SCP. I would like to learn how to do so
> >> programatically.


> > every operating system is different, so there's no standard library
> > for spawing external programs.


> >> There seems to be no standard C++ library (such as iostream, strings,
> >> etc) that would do this. I don't know why. Can anyone explain this to
> >> me?


> > ms windows doesn't have naything remotely like fork() or exec() or even
> > a real argv[]. it's basically too hard to do that sort of thing in
> > a standardisable way.


> CreateProcess()


Which isn't anything like fork() or exec(). Not that it would
be too difficult to standardize something---systems differ a lot
in how they handle IO as well, but C and C++ managed to
standardize that.

--
James Kanze
 
Reply With Quote
 
Richard Kettlewell
Guest
Posts: n/a
 
      02-10-2011
Saqib Ali <(E-Mail Removed)> writes:
> I'm writing C++ code that is running on a Solaris system.
>
> From within my C++ program, I need to copy files from one machine to
> another using SFTP or SCP. I would like to learn how to do so
> programatically.
>
> There seems to be no standard C++ library (such as iostream, strings,
> etc) that would do this. I don't know why. Can anyone explain this to
> me? Without such a library, it seems my only option would be to run an
> operating system call. However if I did so, a user would need to type
> in a password during execution. That seems sub-optimal.


Use a key pair for authentication; invoke scp via system(); use
ssh-agent to avoid repeatedly entering the passphrase that protects the
private key. (Or have no passphrase protecting it, if that's acceptably
secure for your environment.)

--
http://www.greenend.org.uk/rjk/
 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      02-10-2011

"James Kanze" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Feb 10, 12:37 pm, "Paul" <(E-Mail Removed)> wrote:
>> "Jasen Betts" <(E-Mail Removed)> wrote in message

>
>> news:ij0io3$nqb$(E-Mail Removed)...

>
>> > On 2011-02-10, Saqib Ali <(E-Mail Removed)> wrote:

>
>> >> I'm writing C++ code that is running on a Solaris system.

>
>> >> From within my C++ program, I need to copy files from one machine to
>> >> another using SFTP or SCP. I would like to learn how to do so
>> >> programatically.

>
>> > every operating system is different, so there's no standard library
>> > for spawing external programs.

>
>> >> There seems to be no standard C++ library (such as iostream, strings,
>> >> etc) that would do this. I don't know why. Can anyone explain this to
>> >> me?

>
>> > ms windows doesn't have naything remotely like fork() or exec() or even
>> > a real argv[]. it's basically too hard to do that sort of thing in
>> > a standardisable way.

>
>> CreateProcess()

>
> Which isn't anything like fork() or exec().


Since you disputing the similarities what is the difference between
createprocess and fork?

<snip>

 
Reply With Quote
 
Jasen Betts
Guest
Posts: n/a
 
      02-11-2011
On 2011-02-10, Paul <(E-Mail Removed)> wrote:
>
> "Jasen Betts" <(E-Mail Removed)> wrote in message
> news:ij0io3$nqb$(E-Mail Removed)...
>> On 2011-02-10, Saqib Ali <(E-Mail Removed)> wrote:
>>>
>>> Hi.
>>>
>>> I'm writing C++ code that is running on a Solaris system.

>>
>>> From within my C++ program, I need to copy files from one machine to
>>> another using SFTP or SCP. I would like to learn how to do so
>>> programatically.

>>
>> every operating system is different, so there's no standard library
>> for spawing external programs.
>>
>>> There seems to be no standard C++ library (such as iostream, strings,
>>> etc) that would do this. I don't know why. Can anyone explain this to
>>> me?

>>
>> ms windows doesn't have naything remotely like fork() or exec() or even
>> a real argv[]. it's basically too hard to do that sort of thing in
>> a standardisable way.
>>

> CreateProcess()


like I said nothing like fork or exec, no argv[] support.

(posix allows passing an array if arbitrary NUL-terminated strings via argv
windows doesn't, some things can be done by using quote marks but this
is not a general solution, and different things interpret quote marks
in the command-line differently)

--
⚂⚃ 100% natural
 
Reply With Quote
 
Jasen Betts
Guest
Posts: n/a
 
      02-11-2011
On 2011-02-10, Paul <(E-Mail Removed)> wrote:

>>> > ms windows doesn't have naything remotely like fork() or exec() or even
>>> > a real argv[]. it's basically too hard to do that sort of thing in
>>> > a standardisable way.

>>
>>> CreateProcess()

>>
>> Which isn't anything like fork() or exec().

>
> Since you disputing the similarities what is the difference between
> createprocess and fork?


The most obvious differene is the number of parameters, fork takes none.

fork creates as a child, a clone of the running process

The clone interprets all the heritable handles and all the other state
of the parent process (all the structures in memory)

(it's not really a copy, the memory pages are just marked "shared" and
"copy-on-write") so if the child doesn't do much before giving up the
context (eg by calling exec() or or exit() ) there's not a large overhead
associated with the fork call.

Exec() does many of the lesser things createprocess() does, but the big
thing, it oesn't do. it does not create a new process, it recycles
the current one, this can be useful if you want to tweak the
environment a bit before starting some other process, or if you want
to renew the current context without explicitly undoing all the stuff
you've done and without your invoker seeing you exit.

--
⚂⚃ 100% natural
 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      02-11-2011

"Jasen Betts" <(E-Mail Removed)> wrote in message
news:ij36ta$e65$(E-Mail Removed)...
> On 2011-02-10, Paul <(E-Mail Removed)> wrote:
>
>>>> > ms windows doesn't have naything remotely like fork() or exec() or
>>>> > even
>>>> > a real argv[]. it's basically too hard to do that sort of thing in
>>>> > a standardisable way.
>>>
>>>> CreateProcess()
>>>
>>> Which isn't anything like fork() or exec().

>>
>> Since you disputing the similarities what is the difference between
>> createprocess and fork?

>
> The most obvious differene is the number of parameters, fork takes none.
>
> fork creates as a child, a clone of the running process
>
> The clone interprets all the heritable handles and all the other state
> of the parent process (all the structures in memory)
>
> (it's not really a copy, the memory pages are just marked "shared" and
> "copy-on-write") so if the child doesn't do much before giving up the
> context (eg by calling exec() or or exit() ) there's not a large overhead
> associated with the fork call.
>
> Exec() does many of the lesser things createprocess() does, but the big
> thing, it oesn't do. it does not create a new process, it recycles
> the current one, this can be useful if you want to tweak the
> environment a bit before starting some other process, or if you want
> to renew the current context without explicitly undoing all the stuff
> you've done and without your invoker seeing you exit.
>
> --
> ⚂⚃ 100% natural


Yes ok they are different but basically they all create a new process. There
is still a similarity given that do you not agree. IDK if createprocess can
create a child process of its parent or if there is soem other win fucntion
that can do this.



 
Reply With Quote
 
James H. Markowitz
Guest
Posts: n/a
 
      02-11-2011
On Wed, 09 Feb 2011 20:53:38 -0800, Saqib Ali wrote:

> Hi.
>
> I'm writing C++ code that is running on a Solaris system.
>
> From within my C++ program, I need to copy files from one machine to
> another using SFTP or SCP. I would like to learn how to do so
> programatically.
>
> There seems to be no standard C++ library (such as iostream, strings,
> etc) that would do this. I don't know why. Can anyone explain this to
> me? Without such a library, it seems my only option would be to run an
> operating system call. However if I did so, a user would need to type in
> a password during execution. That seems sub-optimal.
>
> I wish there was a function that looked like this:
>
> scp(sourceFile, targetMachine, targetUser, targetPassword, targetFile)
>
> What do other people do in this situation?
>
> Thanks much.
> - Saqib


Use libssh or libssh2. Google will tell you more.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
SCP did not finish successfully () (Net::SCP::Error Une Bvue Ruby 0 07-22-2008 04:26 PM
Maven using ANT plugin for SCP task : Embedded error: Could not create task or type of type: scp. krabhi Java 1 08-09-2006 04:19 PM
scp crit 2 mark | r HTML 7 12-15-2005 04:55 PM
Classes SSH-SCP for Java Xavier Java 9 11-05-2004 02:00 PM



Advertisments