FTP command and use

Source: Internet
Author: User
Tags ftp commands ftp client ftp protocol

FTP command

If you want to write an FTP client program, you must first understand the commands and usage in the FTP protocol.

FTP commands

The following are the FTP commands:

User <SP> <username> <CRLF> logon Username
Pass <SP> <password> <CRLF> Password
Acct <SP> <account-Information> <CRLF>
CWD <SP> <pathname> <CRLF> change the current directory
Cdup <CRLF> returns the parent directory
SMNT <SP> <pathname> <CRLF>
Quit <CRLF> quit
Rein <CRLF> log on again
Port <SP> PASV <CRLF> obtains the data transmission Port
Type <SP> <type-code> <CRLF> set the data exchange type {A (scii), E (bcdic), I (mage), L (ocal byte size )}
Stru <SP> <structure-code> <CRLF>
Mode <SP> <mode-code> <CRLF>
RETR <SP> <pathname> <CRLF>
Stor <SP> <pathname> <CRLF> upload a file to the server in overwrite Mode
STOU <CRLF>
Appe <SP> <pathname> <CRLF> append an object to the server
Allo <SP> <Decimal-integer>
[<SP> r <SP> <Decimal-integer>] <CRLF>
Rest <SP> <marker> <CRLF> specifies the number of bytes that are stored again.
RNFR <SP> <pathname> <CRLF> specifies the original file to be renamed
RNTO <SP> <pathname> <CRLF> specifies the new file name to be renamed.
Abor <CRLF> cancels the previous command
Dele <SP> <pathname> <CRLF> delete a specified file on the server
RMD <SP> <pathname> <CRLF> Delete the specified directory on the server
MKD <SP> <pathname> <CRLF> create a directory on the server
PWD <CRLF> displays the current directory
List [<SP> <pathname>] <CRLF> list all files and subdirectories in the current directory
NLST [<SP> <pathname>] <CRLF> lists the names of all files and subdirectories in the current directory.
Site <SP> <string> <CRLF>
Syst <CRLF>
Stat [<SP> <pathname>] <CRLF>
Help [<SP> <string>] <CRLF> get help
Noop <CRLF>

FTP security commands and arguments

Auth <SP> <mechanic-Name> <CRLF>
Adat <SP> <base64data> <CRLF>
Prot <SP> <prot-code> <CRLF>
Pbsz <SP> <Decimal-integer> <CRLF>
MIC <SP> <base64data> <CRLF>
Conf <SP> <base64data> <CRLF>
ENC <SP> <base64data> <CRLF>

<Mechanic-name >::=< string>
<Base64data >::= <string>
; Must be formatted as described in section 9
<Prot-code >::= c | S | E | P
<Decimal-integer>: = any decimal integer from 1 to (2 ^ 32)-1

 

The above are some commands supported by the FTP protocol. The following describes some examples.

FTP commands

The following is an example of a successful Serv-U test using telnet.

Download files
---------------------------------------------------------------------------
Telnet 127.0.0.1 21
220 Serv-u ftp server v4.0 for Winsock ready...

User admin
331 user name Okay, need password.

Pass ****
230 user logged in, proceed.

PASV
227 entering passive mode <127,0, 4,191,>

Rest 0
350 restarting at 0. Send store or retrieve.

RETR test.rar
150 opening ASCII mode data connection for test.rar <94370 bytes>.
226 transfer complete.

 

Upload files in overwriting Mode
---------------------------------------------------------------------------
Telnet 127.0.0.1 21
220 Serv-u ftp server v4.0 for Winsock ready...

User admin
331 user name Okay, need password.

Pass ****
230 user logged in, proceed.

Stor test. dat
150 opening ASCII mode data connection for test. dat

PASV
227 entering passive mode <127,0, 4,191,>

... Create another connection to the specified port and send data to it...

 

Upload files by append
---------------------------------------------------------------------------
Telnet 127.0.0.1 21
220 Serv-u ftp server v4.0 for Winsock ready...

User admin
331 user name Okay, need password.

Pass ****
230 user logged in, proceed.

Appe test. dat
150 opening ASCII mode data connection for test. dat

PASV
227 entering passive mode <127,0, 4,191,>

... Create another connection to the specified port and send data to it...

 

Rename files and directories
---------------------------------------------------------------------------
Telnet 127.0.0.1 21
220 Serv-u ftp server v4.0 for Winsock ready...

User admin
331 user name Okay, need password.

Pass ****
230 user logged in, proceed.

RNFR sss.rar
350 file or directory exists; ready for destination name

RNTO stock.rar
250 RNTO command successfull.

 

Delete an object
---------------------------------------------------------------------------
Telnet 127.0.0.1 21
220 Serv-u ftp server v4.0 for Winsock ready...

User admin
331 user name Okay, need password.

Pass ****
230 user logged in, proceed.

Dele test. dat
250 DELE Command successfull.

 

Create and delete directories
---------------------------------------------------------------------------
Telnet 127.0.0.1 21
220 Serv-u ftp server v4.0 for Winsock ready...

User admin
331 user name Okay, need password.

Pass ****
230 user logged in, proceed.

MKD mydir
257 "/mydir" directory created.

RMD mydir
250 RMD Command successfull.

 

Disconnect
---------------------------------------------------------------------------
Telnet 127.0.0.1 21
220 Serv-u ftp server v4.0 for Winsock ready...

User admin
331 user name Okay, need password.

Pass ****
230 user logged in, proceed.

Quit
221 goodbye!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.