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 |
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") |
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. |
can you show the code you have written?
|
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; } |
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?
|
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; } |
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") |
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 |
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") |
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" -- |
that is written on the page: nControl is the return value, you will get a handle which can be used to initiate data transfers.
|
i got that point.
but if i call like this,giving only one argument,it gives error like Code:
/* 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 -- |
that is written, you do not understand: you must give a second argument, which is a pointer:
Code:
netbuf *nControl; |
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(...)) |
All times are GMT -5. The time now is 10:02 AM. |