Improve company productivity with a Business Account.Sign Up

x
?
Solved

free SFTP library

Posted on 2004-03-31
8
Medium Priority
?
1,381 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
8 Comments
 
LVL 46

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 1000 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
Become an IT Security Management Expert

In today’s fast-paced, digitally transformed world of business, the need to protect network data and ensure cloud privacy has never been greater. With a B.S. in Network Operations and Security, you can get the credentials it takes to become an IT security management expert.

 
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

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

585 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