LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   c code to login to ftp server while reading all login info from a file (https://www.linuxquestions.org/questions/programming-9/c-code-to-login-to-ftp-server-while-reading-all-login-info-from-a-file-4175412185/)

yahoosam 06-22-2012 06:30 AM

/Error Detail/
Code:

Here's the Login Details:
IP:192.168.1.138
USER:root
PASS:rootroot

####**Connected Successfully**####
      Host : 192.168.1.138
Loged In Successfully
USER root
^C
[root@MyPC/amit]#

/*so i needed to quit the process all the time of execution*/

pan64 06-22-2012 06:52 AM

1. please use [code][/code] to keep formatting
2. do not nest if statements, use: if <something> { handle error and exit } if <something else> { handle error and exit }
3. try to explain what's happened: Did FtpGet create a file, what was the content.
4. call FtpClose at the end.
5. Probably you need to start with FtpInit.
6. try FtpLastResponse to read message and print it, maybe you can find something useful in it

colucix 06-23-2012 01:43 AM

Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

yahoosam 06-25-2012 04:05 AM

Dear pan64:
on the basis of CURL library implementation in program
http://curl.haxx.se/libcurl/c/ftpget.html
& in
http://curl.haxx.se/libcurl/c/ftpupload.html
can u please assist using these functions of library in this url http://nbpfaus.net/~pfau/ftplib/ftplib.html

means which functions will be called after which function(just for GET & PUT operations).
i gave the whole half day on learning CURL-library but i didn't find equivalent functions in both of them.
please assist me.

pan64 06-25-2012 04:22 AM

actually they are really hard to compare, but:
you can use the main function of ftpget.html to implement your ftpget, you need to modify it to pass user/password/url. Also the second link can be used as a base for your ftpput.

yahoosam 06-26-2012 05:51 AM

i went through long way in this project and finally using CURL itself..
all the work i have joined intact.but a little doubt as i am doing all the stuffs as being anonymous user
i.e i need not to put "user" & "pass"
thats why unable to go to root directory..can u plz help me out on the case where to pass USER & PASS for being able to access root directory..
--

pan64 06-26-2012 05:56 AM

I do not really understand it, but here is the way to set user and/or pw: use curl_easy_setopt. See http://curl.haxx.se/libcurl/c/curl_e...URLOPTUSERNAME and http://curl.haxx.se/libcurl/c/curl_e...URLOPTPASSWORD

I hope this helps

yahoosam 06-26-2012 09:24 AM

i tried hard to learn from there...
i got to know while googling that there is a "ftplib-3.1-1 project" which used CURL library but its using EditLine.
so can you go through netkit-ftp_0.17.orig.tar.gz
just only login part,that how it enables login through CURL library.
--
meet you tomorrow

pan64 06-26-2012 11:43 AM

I'm not really sure what ftplib is that, next time please give some links also. I found this, there is an example at the end, probably helps:
http://cboard.cprogramming.com/c-pro...-possible.html

yahoosam 06-27-2012 03:46 AM

Dear pan64:
i did it sir!!

from the first hour onwards i continuously read CURL Tutorial..
in password section it was give..
i had to just add one more curl_easy_setopt before giving url of the file to GET
i.e.

Code:

curl_easy_setopt(curl, CURLOPT_USERPWD, "root:rootroot");

--
thnx for ur long support

pan64 06-27-2012 03:51 AM

great! good job.

yahoosam 07-11-2012 02:16 AM

dear pan64:
Actually i got stuck in one thing..Actually i need advice on that..
In the program
http://curl.haxx.se/libcurl/c/ftpupload.html
i am using this program to transfer multiple files..
and passing all the required variables LOCAL_FILE,UPLOAD_FILE_AS,RENAME_FILE_TO,REMOTE_URL..through linked list

so finally its all working in while loop..but there's a function "curl_slist_append()" which isn't working..
please have a look on that..

pan64 07-11-2012 02:20 AM

what do you mean by "not working"? What is the real code and what happened?

yahoosam 07-11-2012 03:56 AM

Actually my sir told me...what in the case if someone(user) try to send multiple files.
for that i made a while loop which feeds these variables "LOCAL_FILE,UPLOAD_FILE_AS,RENAME_FILE_TO,REMOTE_URL"..

but for each file transfer Curl Authenticates in function:
Code:

curl_easy_setopt(curl, CURLOPT_USERPWD, authentication);
& i am passing "authentication" through a variable,which is same for all transfers
sir told me in Real Time it is not acceptable..
so i need to ask what modification should i do,so that authentication part is done once and all other transfers are being executed as the loop goes.

yahoosam 07-12-2012 02:11 AM

yup! i did that.. might be helpful for others
just made my authentication function before start of while loop..

Code:

curl_easy_setopt(curl, CURLOPT_USERPWD, authentication);

while(1)
{
/*
 *code for transfer
 */
}

& its working fully.. & i also had to clear the value of "headerlist" in here

Code:

if(curl) {
                  headerlist=NULL;
                  ------
                  ------
        }



All times are GMT -5. The time now is 10:10 AM.