LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 06-19-2012, 01:34 AM   #1
yahoosam
Member
 
Registered: Jun 2012
Posts: 79

Rep: Reputation: Disabled
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
 
Old 06-19-2012, 01:59 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,901

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
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")
 
Old 06-19-2012, 04:58 AM   #3
yahoosam
Member
 
Registered: Jun 2012
Posts: 79

Original Poster
Rep: Reputation: Disabled
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.
 
Old 06-19-2012, 06:05 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,901

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
can you show the code you have written?
 
Old 06-19-2012, 07:23 AM   #5
yahoosam
Member
 
Registered: Jun 2012
Posts: 79

Original Poster
Rep: Reputation: Disabled
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;
}
 
Old 06-19-2012, 10:43 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,901

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
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?
 
Old 06-20-2012, 02:14 AM   #7
yahoosam
Member
 
Registered: Jun 2012
Posts: 79

Original Poster
Rep: Reputation: Disabled
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;
}
 
Old 06-20-2012, 02:36 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,901

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
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")
 
Old 06-20-2012, 06:32 AM   #9
yahoosam
Member
 
Registered: Jun 2012
Posts: 79

Original Poster
Rep: Reputation: Disabled
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
 
Old 06-20-2012, 07:41 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,901

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
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")
 
Old 06-22-2012, 12:50 AM   #11
yahoosam
Member
 
Registered: Jun 2012
Posts: 79

Original Poster
Rep: Reputation: Disabled
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"
--
 
Old 06-22-2012, 01:21 AM   #12
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,901

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
that is written on the page: nControl is the return value, you will get a handle which can be used to initiate data transfers.
 
Old 06-22-2012, 01:41 AM   #13
yahoosam
Member
 
Registered: Jun 2012
Posts: 79

Original Poster
Rep: Reputation: Disabled
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.
 
Old 06-22-2012, 01:50 AM   #14
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,901

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
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...
 
Old 06-22-2012, 06:25 AM   #15
yahoosam
Member
 
Registered: Jun 2012
Posts: 79

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
local ftp login OK - remote ftp login failure bluethundr Linux - Newbie 3 08-24-2011 11:13 AM
[Info] emsene: Login Failed: Protocol Not Supported by Server AleLinuxBSD Debian 0 01-18-2010 02:10 PM
FTP Server Up and running... how do I hide ftp users from local login screen? joe1031 Mandriva 2 03-18-2005 04:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration