SunQuest
           FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old October 3rd, 2003, 10:23 AM
ericmar ericmar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 7 ericmar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to write a FTP request

Currently I'm implementing a set of simple client side protocols.
For seding a HTTP request to server, my request is like this:
request = "GET <HOST> HTTP/1.0 /r/n/r/n"

But I dont know how should I write a FTP request for downloading a file. It's operated in binary mode.

Besides, I would like to know how should I implement a FTP client side protocol. Is it like the HTTP protocol? Just do socket(), then connect(), then send request and receive request, and finally do closesocket()? But since FTP is using 2 connection (data & control) so I think should not be the same, right?

I'm a newbie in socket programming. Can anyone helps? I'm writing all these in C++!

Thanks in advance!

Reply With Quote
  #2  
Old October 3rd, 2003, 12:58 PM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 26
some sample commands
Code:
char    *command[] =    //these are the commands we send to ftp server
{
        "USER anonymous\r\n",   
        "PASS asdf@aol.com\r\n",
        "PASV\r\n",             //passive mode for firewalls
        "STOR file\r\n"         //put the file onto the server
};


yes you have the general idea correct. the problem with transferring files is solved with the PASV command. in response to that the server will send you back it's ip and port number, than you connect to that to do the transfer. here is an example of one way to parse that reply,
Code:
case 2:         //PASV command; this causes the server to send us the port number
                                        //that it opens for us to connect to, we log this for the next command
                                if( (buf[0] == '4') || (buf[0] == '5') )
                                {
                                        printf(buf);    
                                        return 0;       
                                }

                                //parse the reply and extract port number; format: (195,167,65,228,9,170).
                                //start from the end and count 3 commas to get here--------------/
                                //then add 2 to that to point at first byte of port (network byte ordered)
                                y = 0;
                                len = strlen(buf);
                                tmp = buf + len - 1;    //the last nonNULL byte of buffer
                                
                                while(y < 3)    //find 2 ',' and 1 ')'
                                {
                                        if( (tmp != NULL) && ( (*tmp == ',') || (*tmp == ')')) )//sanity check b4 dereference
                                        {       
                                                y++;    
                                                *tmp = '\0';    //null terminate to make tokens
                                        }
                                        tmp--;
                                }       //now tmp points 2 bytes behind start of port byte one
                                        
                                tmp += 2;       //move back to first byte of port
                                *port       = (u_char)(atoi(tmp));      //this is byte one
                                *(port + 1) = (u_char)(atoi(tmp + strlen(tmp) + 1));    //byte two
                                da_port =  *(unsigned short *)port;     //the port in n0rdered port 
                                
                                break;


i wrote a couple ftp clients if you want to check them out. well they're not exactly legitamate "clients" but you'll get the idea when you see them lemme know if ya want to check themout.

Reply With Quote
  #3  
Old October 3rd, 2003, 01:06 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,803 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 12 h 1 m
Reputation Power: 437
In network programming, doing the sockets is the easy part. The application-level protocols is the hard part.

FTP is an application-level protocol and it is quite different from HTTP. For one thing, I think that it requires a session (logging on, authenticating, and issuing commands).

Google on FTP protocol. Some of the hits I got are:
The FTP Protocol Resource Center at http://war.jgaa.com/ftp/
Includes some source code and a list of the applicable and related RFCs.

FTP: File Transfer Protocol at http://cr.yp.to/ftp.html

FTP Protocol Related Documents at http://www.wu-ftpd.org/rfc/
wu-ftpd is the usual ftp server on Linux.


Anyway, my Google search found over 3 million hits, so I suggest that your own Google would be a good place to start.

BTW, RFC 959 appears to be the principal document governing how FTP is supposed to work and be used. You will definitely need to become familiar with it.

Last edited by dwise1_aol : October 3rd, 2003 at 01:18 PM.

Reply With Quote
  #4  
Old October 3rd, 2003, 01:08 PM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 26
yea i almost forgot, definitly read the RFC. that's how i figured all the junk out.

Reply With Quote
  #5  
Old October 3rd, 2003, 07:45 PM
ericmar ericmar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 7 ericmar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks guys...

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > How to write a FTP request


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway