Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
06-19-2012, 01:34 AM
|
#1
|
|
Member
Registered: Jun 2012
Posts: 76
Rep: 
|
c code to login to ftp server while reading all login info from a file
i am urgently in need of a c code for my B.Tech. last sem project, while will read ftp server login info like IP,user name,password from a file and log in to ftp server...
gotta urgent
|
|
|
|
06-19-2012, 01:59 AM
|
#2
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,745
|
do you have a test code or something to start with?
_____________________________________
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Happy with solution ... mark as SOLVED
(located in the "thread tools")
|
|
|
|
06-19-2012, 04:58 AM
|
#3
|
|
Member
Registered: Jun 2012
Posts: 76
Original Poster
Rep: 
|
i just wrote a program to just read a file as the file will store all the necessary inputs for login like IP,User,Pass.
and stored in structure but dont know to which should i pass these arguments for login.i already have created an FTP server by installing "VSFTPD package"..can u assist on this.
|
|
|
|
06-19-2012, 06:05 AM
|
#4
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,745
|
can you show the code you have written?
|
|
|
|
06-19-2012, 07:23 AM
|
#5
|
|
Member
Registered: Jun 2012
Posts: 76
Original Poster
Rep: 
|
its just reading program from the file nothing much..
structure wise
#include /*Header files*/
typedef struct
{
char ip;
char user;
char pass;
}info;
main()
{
FILE *fp;/*file to read details*/
info *data=NULL;
a=data->ip;
b=data->user;
c=data->pass;
/*Required method to pass these arguments*/
methodLogin(a,b,c);/*At this point i need assistance for my semester project as i thought to do*/
return 0;
}
|
|
|
|
06-19-2012, 10:43 AM
|
#6
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,745
|
yes, you need to open file and parse data. here is a little example on how to open and read a file using fopen and fscanf. Can you fill up the ip, user and pass variables?
|
|
|
|
06-20-2012, 02:14 AM
|
#7
|
|
Member
Registered: Jun 2012
Posts: 76
Original Poster
Rep: 
|
i did writing & modification for the parse program as here..
so what further in case the login to FTP commented below!!
#include <stdio.h>
//#include <io.h>
#include <stdlib.h>
#include<string.h>
typedef struct
{
char ip[16];
char user[16];
char pass[16];
}info;
int main(void)
{
FILE *fp;
/*
char ip[16];
char user[16];
char pass[16];
int t;
*/
info *value=NULL;
value=(info *)malloc(sizeof(info));
memset(value,0,sizeof(info));
if((fp=fopen("test", "w")) == NULL) {
printf("Cannot open file.\n");
exit(1);
}
printf("Enter IP,USER,PASS: ");
fscanf(stdin, "%s %s %s",value->ip,value->user,value->pass); /* read from keyboard */
fprintf(fp, "%s %s %s", value->ip,value->user,value->pass); /* write to file */
fclose(fp);
if((fp=fopen("test","r")) == NULL) {
printf("Cannot open file.\n");
exit(1);
}
fscanf(fp, "%s %s %s", value->ip,value->user,value->pass); /* read from file */
fprintf(stdout, "IP:%s\nUSER:%s\nPASS:%s\n\n", value->ip,value->user,value->pass); /* print on screen */
/*FTP LOGIN*/
FtpLogin(value->ip,value->user,value->pass);
return 0;
}
|
|
|
|
06-20-2012, 02:36 AM
|
#8
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,745
|
There are some problems with your code, but first: please use [code][/code] to keep formatting your code.
1. probably 16 bytes are not enough to store ip/user/pass. In case of overflow your app may die with a segmentation fault or similar, or will destroy some data inside.
2. you did not check the result of fscanf.
3. here is a simple ftp client: http://enggedu.com/lab_exercise/netw...FTP_client.php. With this you can connect to a server.
4. you can try to log in, send commands and receive response.
_____________________________________
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Happy with solution ... mark as SOLVED
(located in the "thread tools")
|
|
|
|
06-20-2012, 06:32 AM
|
#9
|
|
Member
Registered: Jun 2012
Posts: 76
Original Poster
Rep: 
|
pan64:Actually i m in need of some FTP API functions which will logon with my attributes,send files(PUT),recieve files{GET},and then exits.thats my idea of project..
now can u assist me on that as at this level m not vrt good at Googling..
--
Respond
|
|
|
|
06-20-2012, 07:41 AM
|
#10
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,745
|
here is an api, but you need to compile it. I assume it will not cause any problem.
Also a collection: http://curl.haxx.se/libcurl/competitors.html. Libcurl has a few example also: http://curl.haxx.se/libcurl/c/ftpupload.html
_____________________________________
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Happy with solution ... mark as SOLVED
(located in the "thread tools")
|
|
|
|
06-22-2012, 12:50 AM
|
#11
|
|
Member
Registered: Jun 2012
Posts: 76
Original Poster
Rep: 
|
Thanx vry much!
i m going through all the APIs n got stuck in one argument.i m giving u the url of function and argument i stuck with.
function URL:
http://nbpfaus.net/~pfau/ftplib/FtpConnect.html
Problem:
int FtpConnect(const char *host, netbuf **nControl);
what to pass here for "netbuf **nControl"
--
|
|
|
|
06-22-2012, 01:21 AM
|
#12
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,745
|
that is written on the page: nControl is the return value, you will get a handle which can be used to initiate data transfers.
|
|
|
|
06-22-2012, 01:41 AM
|
#13
|
|
Member
Registered: Jun 2012
Posts: 76
Original Poster
Rep: 
|
i got that point.
but if i call like this,giving only one argument,it gives error like
Code:
/*
if(!FtpConnect(value->ip))
{
printf("Error in connection");
}
Error:
parse.c: In function ‘main’:
parse.c:52: error: too few arguments to function ‘FtpConnect’
*/
so wat structure ref should i pass there..
will u please write that function with its passing arguments.with that argument declaration.
coz for last 2hrs i am searching for "Arguments for FtpConnect" in google and result is ZERO
--
Last edited by yahoosam; 06-26-2012 at 01:27 AM.
|
|
|
|
06-22-2012, 01:50 AM
|
#14
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,745
|
that is written, you do not understand: you must give a second argument, which is a pointer:
Code:
netbuf *nControl;
if(!FtpConnect(value->ip, &nControl))
{
printf("Error in connection");
}
// this nControl will identify your connection and will be used as a handle in the subsequent calls you will make...
|
|
|
|
06-22-2012, 06:25 AM
|
#15
|
|
Member
Registered: Jun 2012
Posts: 76
Original Poster
Rep: 
|
just perfectly fine and running successfully..
jst got stuck in sending & receiving files..Actually program halts at some point after entering to the function FtpGet(...)
Putting Rough structure in here,have a look on FtpGet() function plz
giving you details..
Code:
if(FtpConnect(...))
{
if(FtpLogin(...))
{
if(FtpGet("abc.c","/home/amit/ftp/llllll.c",FTPLIB_ASCII,nControl))/*Take an Eye in here*/
/*About FtpGet()
http://nbpfaus.net/~pfau/ftplib/FtpGet.html
*/
{
printf("Sent successfully");
}else{ printf("can't send"); exit(0);}
}else{ printf("can't Login"); exit(0);}
}else{ printf("can't Connect"); exit(0);}
Last edited by yahoosam; 06-26-2012 at 01:28 AM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:29 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|