Solved

free SFTP library

Posted on 2004-03-31
8
1,366 Views
Last Modified: 2007-12-19
Hello,

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

Thanks
0
Comment
Question by:s_federici
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 10724004
Hi s_federici,


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



Kent
0
 
LVL 24

Accepted Solution

by:
fridom earned 250 total points
ID: 10724682
You might want to check libcurl from
http://curl.haxx.se/libcurl/

Regards
Friedrich
0
 

Author Comment

by:s_federici
ID: 10725002
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:anupvijay
ID: 10725429
Hi federici,

Just got another link for you. Might be helpful.

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

Cheers,
Anup
0
 

Author Comment

by:s_federici
ID: 10726872
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
 
LVL 24

Expert Comment

by:fridom
ID: 10732014
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
 
LVL 24

Expert Comment

by:fridom
ID: 10732027
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
 

Author Comment

by:s_federici
ID: 10732406
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question