Solved

free SFTP library

Posted on 2004-03-31
8
1,359 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 45

Expert Comment

by:Kdo
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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 how to use strings and some functions related to them in the C programming language.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now