free SFTP library

Hello,

Can anyone recomend a good, free SFTP (secure ftp) library in C or C++ or (best even if... unlikely) Tcl?

Thanks
s_federiciAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
fridomConnect With a Mentor Commented:
You might want to check libcurl from
http://curl.haxx.se/libcurl/

Regards
Friedrich
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi s_federici,


Sure.  Start with openssh.  You can get to their source code via www.openssh.com



Kent
0
 
s_federiciAuthor Commented:
Friedrich,
libcurl seems EXACTLY what I need. It is only a little obscure (maybe due to the fact that I only took a look at it) how I can use it to perform secure ftp. But the Tcl bindings are there.

Before I can assign you the points I need to spend some time to see if it will work for me or (if you will be so kind) maybe you can send me a few examples or pointers to them.
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
anupvijayCommented:
Hi federici,

Just got another link for you. Might be helpful.

http://www.chiark.greenend.org.uk/~sgtatham/putty/

Cheers,
Anup
0
 
s_federiciAuthor Commented:
As far as I understand, putty is a command line interface, not a library. I have to realize an SFTP connection programmatically with password and without supervision. And if I correctly understood, with putty I should interact with a shell to insert the password. Am I wrong? If so, please send me an example of usage.
0
 
fridomCommented:
Well libcurl has probalbly the easiest interface to understand.  here's an example fetching a page with HTTP:
static int fetch_simple_page (CURL *curl){
      CURLcode res;
      char err_buf [2* CURL_ERROR_SIZE];
      char simple_text_url [] = "http://localhost/~frido/libcurl-examples/simple.txt";
      res = curl_easy_setopt(curl, CURLOPT_URL, simple_text_url);
      if (CURLE_OK != res){
            goto error;
      }
      res = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, err_buf);
      if (CURLE_OK != res){
            goto error;
      }
      res = curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, my_fwrite);
      if (CURLE_OK != res){
            goto error;
      }
      res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &my_file);
      res = curl_easy_perform(curl);
      if (CURLE_OK != res){
            goto error;
      }
    return 1;
      error:
            fprintf(stderr, "curl error: %s\n", err_buf);
            return 0;

}

Well the base line is: You initailize the library, you set some options, in first line what URL you want to fetch, what write function you want to use (you can e.g write to memory mapped files, or "normal" files, do as you like) then you say ..._perform and the page is fetched.

Here's a complete example of an FTP download (without error handling this time, it shows how a user and password can be sent. AFAIK does it work for SFTP too.
#include <stdio.h>
#include <curl/curl.h>



static int fetch_simple_page (CURL *curl){
      CURLcode res;
    FILE *my_file = fopen("LCC_README", "w");
      char simple_text_url [] = "ftp://ftp:someone.somwhere@www.q-software-solutions.com/pub/lcc/README";
      res = curl_easy_setopt(curl, CURLOPT_URL, simple_text_url);
    res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
    // res = curl_easy_setopt(curl, CURLOPT_VERBOSE);
      res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, my_file);
      res = curl_easy_perform(curl);
    fclose(my_file);
    return 1;
}


int main(void)
{
  CURL *curl;
  int irval = 0;


  curl = curl_easy_init();
  if(curl) {
    irval = fetch_simple_page(curl);
      if (irval){
      puts("Got the page");
       }


    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  curl_global_cleanup();
  return 0;
}

You may want to visit http://curl.haxx.se/libcurl if you need assitance with libcurl development. Well if you like you can find out my address and I'll see what I can do for you.

Regards
Friedrich

0
 
fridomCommented:
Well a sort of follow-up, you can use pscp or scp or rsync for copying files it takes username etc but that's a command line tool, if you want to use such a thing you might want to check curl and wget too.

Regards
Friedrich
0
 
s_federiciAuthor Commented:
I'm definitely going to try libcurl (in the Tcl version I think). In the meantime I'm going to assign to you the full points (the command line tools suggested in the other answers are not what I was looking for). Please, allow me to bother you with some follow ups if I'm in trouble with it.
0
All Courses

From novice to tech pro — start learning today.