Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need URGENT help wit FTP Programming

Status
Not open for further replies.

cpbee

Programmer
Dec 27, 2001
3
CH
Hello,

I need help for some FTP programming. I tried some other places, but nobody could help me. So my prob is: I want to code some FTP Client, that automatically downoads some stuff from a site. The whole thing should be or is started in WinAPÎ... with raw Sockets. I mangaged to get a connection to the FTP server, also the login and password submission works fine. The problem starts with some more advanced commands. Like List and / or Retrieve. I know the commands (got them from the RFC 959) but somehow I don't get them working. If I call for the "LIST" command, it arrives at the server, but I don't get any answer.
What do I wrong? Could anybody help me with that specific problem? Does anybody know a source of FTP Client that uses Raw Sockets?

I would be very thankful if anybody could help me!!!

chris.

(Here is some code I use.. "send" sends the message and I capture the server answer with "retrv").

bool TheFTP::entrPassv()
{
int pos;
//Set Current Working directory
sprintf(message,"CWD\r\n");
send(s,message,strlen(message),0);
getServerAnswer();

//Print Current Working directory
sprintf(message,"pwd\r\n");
send(s,message,strlen(message),0);
getServerAnswer();

//Set to Binary Mode
sprintf(message,"TYPE A\r\n");
send(s,message,strlen(message),0);
getServerAnswer();

//get Passive Mode IP and Port
sprintf(message,"PASV \r\n");
send(s,message,strlen(message),0);
getServerAnswer();

//get Passive Mode stuff
pos=strcspn(bf,"(");
sprintf(passivePort,&bf[pos+1]);
pos=strlen(passivePort);
passivePort[pos-3]='\0';
/*
//set Passive Mode Port
sprintf(message,"PORT *********\r\n");
//strcat(message,passivePort);
//strcat(message,"\r\n");
send(s,message,strlen(message),0);
getServerAnswer();

*/
getDirList();

return true;
}

bool TheFTP::getDirList()
{

sprintf(message,"LIST\r\n");
send(s,message,strlen(message),0);

getServerAnswer();


return true;

}
 
Is there an Error code sent Back from the server?

Consider FTP uses 2 Channels 21 for Commands and 20 for Data.
hnd
hasso55@yahoo.com

 
and how do I exactly manage that? I would appreciate your help!

Thx chris.
 
Each command is confirmed by an response code sent back by the FTP-Server.
For Example 200 means Command Ok.
In the first step you should check this code to find out the reason why this command is not working.

The other thing: To implement a FTP-Client look to the WinInet-API there are a lot of encapsulated Functions you could use (if you are using Windows)

What i would do: Take an ftp-client that support Command line parameters and launch it from a regular program.

In an Unix-Environment you could start it from Cron and that would need no line of writing Code.
hnd
hasso55@yahoo.com

 
What i forgot: in a Windows environment, you can start a FTP-Client from a Task - scheduler too.
hnd
hasso55@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top