Good afternoon. I am quite new to C and was playing around with attempting to write my own C based program (compiling w/ gcc via cygwin) to communicate with an FTP server (FileZilla Server version 0.9.41 beta) on 127.0.0.1:21.
I can not seem to be able to read and spit out any output from the FTP server via the program pipelines.
My (what will be an eyesore) code:
================================================
Code:
#include <stdio.h>
#include <time.h>
#include <Windows.h>
#include <unistd.h>
#include <string.h>
//define variables//
char username[20];
char password[20];
char out[50];
int main()
//main function starts here//
{
//obtain user input to apply to FT protocol//
printf("Username to use?\n");
scanf("%s",username);
printf("Password to use?\n");
scanf("%s",password);
//start a write pipeline to ftp from bash shell//
FILE *ftp=popen("ftp","w");
// input the user info and open connection//
fprintf(ftp,"o 127.0.0.1 21 \n%s\n",username);
fprintf(ftp,"%s",password);
//Start read pipe: //
FILE*ftpread=popen("ftp","r");
//obtain any output from FTP//
fscanf(ftpread,"%s",out);
//Program sticks, does not pick up the ftp "bad user/password" (530) output//
//start a write pipeline to ftp from bash shell, for more input if connected//
FILE *ftp3=popen("ftp","w");
// input the user info and open connection//
//Close pipes here?//
pclose(ftp); pclose(ftpread); pclose(ftp3);
getchar();
return EXIT_SUCCESS;
}
==================================================
Braces for n00b flame!
Thanks for any help!