Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   How do to SCP from within my C++ program? (http://www.velocityreviews.com/forums/t743329-how-do-to-scp-from-within-my-c-program.html)

Saqib Ali 02-10-2011 04:53 AM

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

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

Jasen Betts 02-10-2011 11:38 AM

Re: How do to SCP from within my C++ program?
 
On 2011-02-10, Saqib Ali <saqib.ali.75@gmail.com> 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

Paul 02-10-2011 12:37 PM

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

"Jasen Betts" <jasen@xnet.co.nz> wrote in message
news:ij0io3$nqb$1@reversiblemaps.ath.cx...
> On 2011-02-10, Saqib Ali <saqib.ali.75@gmail.com> 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()




James Kanze 02-10-2011 01:03 PM

Re: How do to SCP from within my C++ program?
 
On Feb 10, 12:37 pm, "Paul" <pchris...@yahoo.co.uk> wrote:
> "Jasen Betts" <ja...@xnet.co.nz> wrote in message


> news:ij0io3$nqb$1@reversiblemaps.ath.cx...


> > On 2011-02-10, Saqib Ali <saqib.ali...@gmail.com> 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

Richard Kettlewell 02-10-2011 01:30 PM

Re: How do to SCP from within my C++ program?
 
Saqib Ali <saqib.ali.75@gmail.com> 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/

Paul 02-10-2011 01:33 PM

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

"James Kanze" <james.kanze@gmail.com> wrote in message
news:2d306221-2946-42bb-af21-c656ace78c4b@x11g2000yqc.googlegroups.com...
> On Feb 10, 12:37 pm, "Paul" <pchris...@yahoo.co.uk> wrote:
>> "Jasen Betts" <ja...@xnet.co.nz> wrote in message

>
>> news:ij0io3$nqb$1@reversiblemaps.ath.cx...

>
>> > On 2011-02-10, Saqib Ali <saqib.ali...@gmail.com> 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>


Jasen Betts 02-11-2011 11:02 AM

Re: How do to SCP from within my C++ program?
 
On 2011-02-10, Paul <pchristor@yahoo.co.uk> wrote:
>
> "Jasen Betts" <jasen@xnet.co.nz> wrote in message
> news:ij0io3$nqb$1@reversiblemaps.ath.cx...
>> On 2011-02-10, Saqib Ali <saqib.ali.75@gmail.com> 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

Jasen Betts 02-11-2011 11:35 AM

Re: How do to SCP from within my C++ program?
 
On 2011-02-10, Paul <pchristor@yahoo.co.uk> 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

Paul 02-11-2011 12:22 PM

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

"Jasen Betts" <jasen@xnet.co.nz> wrote in message
news:ij36ta$e65$4@reversiblemaps.ath.cx...
> On 2011-02-10, Paul <pchristor@yahoo.co.uk> 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.




James H. Markowitz 02-11-2011 02:28 PM

Re: How do to SCP from within my C++ program?
 
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.



All times are GMT. The time now is 02:27 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.