Archived

This topic is now archived and is closed to further replies.

anticipating FTP server responses (not exactly networking..)

This topic is 5498 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i'm trying to get a simple ftp client going (to peform a specific purpose for me), but i'm having a problem with something. (btw im using winsock.) when i connect to my friends server through winsock, it sends back a bunch of information. for instance, this is what his sends to me:
quote:
220-JuJuSoft FTP - Run by Derek the Greedy Ju 220-Server Stats: 220- 220-Server has been up for: 7 days 220-Data Leeched From Server: 2341408 KBs 220-Data Uploaded to Server: 302374 KBs 220-2 people are using: 50.000 KB/s 220- 220
as you can see each line begins with 220. this is normal. now, the next step is to send to the server your user/pass info. this is simple. my problem is i want it to wait for the FTP server to send all that initial text to you, before the program sends out the user/pass info. but i dont how to figure out when the FTP server has sent everything it has to. i mean, lets say i try to logon to randomFtpServerX, i dont know how long his 'welcome' msg is, so i dont know how to know when to send the data. there's no terminating character for the entire thing. each line is terminated by the ascii code 13, but that doesn't help me, because i dont know if the ftp server is going to send any more lines after that. how do other ftp clients do this? do they simply write a function in the program to connect, then just wait 1 second, then send out the login info regardless? it doesnt seem so, because every client I use, the login info seems to be sent perfectly, right after the welcome msg has been sent. any help would be appreciated. [edited by - amemorex on November 21, 2002 8:43:42 PM]

Share this post


Link to post
Share on other sites
When you connect to the server, doesn''t your connecting socket get filled with data? Can;t you just keep testing (looping) until theres no data left in the socket? Or does the server send one line and then wait?

Share this post


Link to post
Share on other sites
Doesn't the server send a login prompt?
For example, when I connect to sourceforge, I see the following:


Connected to unc.dl.sourceforge.net.
220 ProFTPD Server (unc.dl.sourceforge.net)
User (unc.dl.sourceforge.netnone)):


Wait for the user name prompt, and then send the user name.
Same for the password.

EDIT - Not sure how to get the frownie to go away. Tried to use code tags, but it didn't help

[edited by - ShawnO on November 22, 2002 9:43:40 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The three digit code specifies the state of the server. i.e. 220 indicates that the server is ready for new user, and you can probably begin sending user login data at any time.

You could send your username login info and check the return code to see if you were successful, and re-send, or react appropriately based upon the return code.

You can find information about the return codes for FTP from RFC959:

http://www.w3.org/Protocols/rfc959

More specifically look at the section titled "4.2. FTP REPLIES" on this page:

http://www.w3.org/Protocols/rfc959/7_Scenario.html

If you are not familiar with RFC''s, you can get more information here:

http://www.faqs.org/rfcs/

Hope that helps.

Cheerio,
Aaron

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
The three digit code specifies the state of the server. i.e. 220 indicates that the server is ready for new user, and you can probably begin sending user login data at any time.

You could send your username login info and check the return code to see if you were successful, and re-send, or react appropriately based upon the return code.

You can find information about the return codes for FTP from RFC959:

http://www.w3.org/Protocols/rfc959

More specifically look at the section titled "4.2. FTP REPLIES" on this page:

http://www.w3.org/Protocols/rfc959/7_Scenario.html

If you are not familiar with RFC''s, you can get more information here:

http://www.faqs.org/rfcs/

Hope that helps.

Cheerio,
Aaron


Oops, that was me....


| HollowWorks.com | Rhott.com |

Share this post


Link to post
Share on other sites
I am writing an FTP server.. for the fun of it.. I think you should use some kind of testing the socket (depends on your choosen IO strategy).. you know that every ftp-session starts with your client receiving some message. okay so after you have connected you recv() from the socket while you check it for read - and writeabitily.. when readability fails and writeability succeeds you should be able to start the login sequence.. just remember to parse the received data for errors before you start the login :-)

Share this post


Link to post
Share on other sites