Re: ssh in C++

From: Tom Roberts <tjrob_at_fnal.gov>
Date: Mon, 11 Aug 2008 20:50:48 -0500


Manungu Kiveni wrote:
> I am writing an application that need to access files remotely, open and
> read the file. The aim is to ptoduce a .dat file format and bring this
> file to my computer (using scp for e.g). My question is how to use ssh in
> C++ to access remote machines.

There are several possibilities, ranging from difficult to simple and straightforward:

  1. Compile the ssh libraries into your code and write C++ code to use them directly.
  2. Use the system() function to run scp on the local computer, explicitly transferring files to and from local copies.
  3. Before starting Root, use sshfs to mount the remote computer's directory locally and then just read and write its files (they appear as if they were local; scp is used to transfer them in a manner hidden to you).
  4. Run root completely locally, using scp manually to transfer files.

As long as both machines can do (C), I highly recommend that method -- it's by far the simplest of A-C, and the most general. It has overheads, but on modern hardware with a reasonably fast network they are not obtrusive unless you use very large files. A major virtue of (C) and (D) is that they are transparent for systems that require a manual cryptocard or other access device for authentication. You will likely find other applications for (C)....

Any reasonably modern Linux or Mac OS machine can be configured to do (C); setup requires root access, but once set up an authorized non-root user can use it. I don't know about Windows. Google can find sshfs (it is based on fuse - file system in user space).

Tom Roberts Received on Tue Aug 12 2008 - 03:51:04 CEST

This archive was generated by hypermail 2.2.0 : Wed Aug 13 2008 - 23:50:01 CEST