View topic - FTP in QNX

FTP in QNX

Discussion about the general applications that run on QNX6

FTP in QNX

Postby amol.madane » Fri Mar 12, 2010 12:41 pm

Hi
I am facing the problem while developing the following functionalities,
1. Establishing the FTP connection by opening the Internet session with the help of server name, username, password, FTP Port number.
2. If there is a problem with the connection then it will log a message.

Please suggest me how to implement the above scenarion in C++ in QNX.

Regards,
Amol
amol.madane
Active Member
 
Posts: 24
Joined: Mon Dec 07, 2009 7:28 am

Postby seanb » Fri Mar 12, 2010 12:57 pm

Maybe look at libcurl. It builds from pkgsrc
or the source from the networking project
on the foundry.

Regards,

-seanb
seanb
QNX Master
 
Posts: 133
Joined: Fri Jul 28, 2006 5:36 pm

Postby amol.madane » Fri Mar 12, 2010 1:03 pm

Thanks for your quick reply.
Please tell from where I can download or get the libcurl.

Regards,
Amol
amol.madane
Active Member
 
Posts: 24
Joined: Mon Dec 07, 2009 7:28 am

Postby seanb » Fri Mar 12, 2010 2:45 pm

amol.madane wrote:Thanks for your quick reply.
Please tell from where I can download or get the libcurl.

Regards,
Amol


Please see my previous post:

"It builds from pkgsrc or the source from the
networking project on the foundry."

Or you can wait for 6.5 which will ship with libcurl.

-seanb
seanb
QNX Master
 
Posts: 133
Joined: Fri Jul 28, 2006 5:36 pm

Postby amol.madane » Wed Mar 24, 2010 9:46 am

I have downloaded the LibCurl from http://curl.haxx.se/download.html for QNX.
In this Library, I have refered the Man page http://curl.haxx.se/docs/manpage.html. Its giving all the commands not API.
So, I am still searching for the specific API for establishing the FTP connection using server name, username, password, FTP Port number.

Please suggest me how to do the same
-Amol
amol.madane
Active Member
 
Posts: 24
Joined: Mon Dec 07, 2009 7:28 am

Postby amol.madane » Wed Apr 07, 2010 5:46 pm

I am able to establish the FTP connection and able to transfer the file using Lib Curl file.
Now, I am facing the problems which are as follows,
1. Single Command used to establish the FTP connection using Username and Password is "ftp ftp://amol:amol@171.224.559.216:21"
But I am unable to establish the connection.
2. I want to search/find the specific file (*.txt) in the given directory using Curl library.

Please help me to solve the issue.
amol.madane
Active Member
 
Posts: 24
Joined: Mon Dec 07, 2009 7:28 am

Postby amol.madane » Thu Apr 08, 2010 5:12 am

Now I am able to establish the FTP connection using single command i.e. ftp "ftp://amol:amol@171.224.559.216:21" .
But still I need to search/find the specific file (*.txt) in the given directory using API of Curl Library.

Any help in finding a solution would be greatly appreciated.!!!!!!!!!
amol.madane
Active Member
 
Posts: 24
Joined: Mon Dec 07, 2009 7:28 am

File transfer using FTP API in QNX

Postby amol.madane » Fri Apr 23, 2010 9:56 am

Hi,

Now, I am able to transfer the single file (whose name is known to me) from server to client after establish the FTP connection from client to server with the help of Lib Curl. The code is as follows,
#include <stdio.h>
#include <curl.h>
#include <types.h>
#include <easy.h>

/*
* This is an example showing how to get a single file from an FTP server.
* It delays the actual destination file creation until the first write
* callback so that it won't create an empty file in case the remote file
* doesn't exist or something else fails.
*/
#define UPLOAD_FILE_AS "11.txt"
#define REMOTE_URL "ftp://172.29.59.216/" UPLOAD_FILE_AS


struct FtpFile
{
const char *filename;
FILE *stream;
};

static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
{
struct FtpFile *out=(struct FtpFile *)stream;
if(out && !out->stream)
{
/* open file for writing */
out->stream=fopen(out->filename, "wb");
if(!out->stream)
return -1; /* failure, can't open file to write */
}
return fwrite(buffer, size, nmemb, out->stream);
}

int main(void)
{
CURL *curl;
CURLcode res;
struct FtpFile ftpfile={"11.txt", NULL}; /* name to store the file as if succesful */
struct curl_slist *headerlist=NULL;
static const char buf_1 [] = "DELE " UPLOAD_FILE_AS;
curl_global_init(CURL_GLOBAL_DEFAULT);

curl = curl_easy_init();

if(curl)
{
/*
* Get curl 7.9.2 from sunet.se's FTP site. curl 7.9.2 is most likely not
* present there by the time you read this, so you'd better replace the
* URL with one that works!
*/

headerlist = curl_slist_append(headerlist, buf_1);
curl_easy_setopt(curl, CURLOPT_URL, REMOTE_URL);
curl_easy_setopt (curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt (curl, CURLOPT_USERNAME , "gaurav");
curl_easy_setopt (curl, CURLOPT_PASSWORD ,"gaurav");

/* Define our callback to get called when there's data to be written */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);

/* Set a pointer to our struct to pass to the callback */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);

/* Switch on full protocol/debug output */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);


curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
res = curl_easy_perform(curl);

/* always cleanup */
curl_easy_cleanup(curl);

if(CURLE_OK != res)
{
/* we failed */
fprintf(stderr, "curl told us %d\n", res);
}
}

if(ftpfile.stream)
fclose(ftpfile.stream); /* close the local file */

curl_global_cleanup();

return 0;
}

But my basic aim is to transfer all the file (whose ext is know to me, not the full file name) in one stroke from server to client.
Please help me to solve this issue.
amol.madane
Active Member
 
Posts: 24
Joined: Mon Dec 07, 2009 7:28 am


Return to QNX6 - Applications

Who is online

Users browsing this forum: No registered users and 6 guests