FTP file transfer service
The client can upload or download files
FTP active mode and FTP passive mode are for the server. The data connection initiated by the server is the active mode, and the data connection request initiated by the server and other clients is the passive mode.
FTP active mode, passive mode_ftp three-way handshake_Yibodong's blog-CSDN blog
First ensure that the client and server can communicate with each other
AR1:
<Huawei>sys
[Huawei]sys AR1
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 10.0.12.1 24
May 9 2023 19:02:57-08:00 AR1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[R1-GigabitEthernet0/0/0]q
AR2:
<Huawei>sys
[Huawei]sys R2
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip add 10.0.12.2 24
May 9 2023 19:05:25-08:00 R2 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[R2-GigabitEthernet0/0/0]q
FTP server configuration:
[R2]ftp server enable //开启ftp服务,默认为关闭,需要手动开启
Info: Succeeded in starting the FTP server
配置ftp用户
[R2]aaa
[R2-aaa]local-user ftpuser password cipher 123 //创建ftpuser用户加密密码123
Info: Add a new user.
[R2-aaa]local-user ftp-client service-type ftp //用户类型为ftp
[R2-aaa]local-user ftp-client privilege level 15 //用户级别为15,用户级别大于等于3级,否则FTP连接将无法成功
[R2-aaa]local-user ftp-client ftp-directory flash:/ //配置本地用户的ftp目录为 "/"
默认缺省 flash: 也是 "/" 目录
client connection
<R1>ftp 10.0.12.2 //ftp 服务器端ip 连接ftp
Trying 10.0.12.2 ...
Press CTRL+K to abort
Connected to 10.0.12.2.
220 FTP service ready.
User(10.0.12.2:(none)):ftpuser //输入用户 ftpuser
331 Password required for ftpuser.
Enter password: //输入密码 123
230 User logged in.
[R1-ftp]
ASCII用于传输纯文本文件,Binary用于传输系统软件、图形图像、声音影像、压缩文件、数据库等程序文件
[R1-ftp]ascii //设置传输模式,不设置默认为ascii
200 Type set to A.
[R1-ftp]dir //查看文件
[R1-ftp]get test2.cfg //get下载文件
200 Port command okay.
150 Opening ASCII mode data connection for test2.cfg.
226 Transfer complete.
FTP: 961 byte(s) received in 0.220 second(s) 4.36Kbyte(s)/sec.
[R1-ftp]put test1.cfg //put上传文件
200 Port command okay.
150 Opening ASCII mode data connection for test1.cfg.
226 Transfer complete.
FTP: 875 byte(s) sent in 0.240 second(s) 3.64Kbyte(s)/sec.
#断开FTP连接
[R1-ftp]bye
221 Server closing.
<R1>
File operations via FTP
- File operations via FTP commands
Action items |
Order |
illustrate |
Change the working path on the server |
cd remote-directory |
- |
Change the server's working path to the upper level directory |
cdup |
- |
Show server working path |
pwd |
- |
Display or change the client's working path |
lcd [ local-directory ] |
The difference from pwd is that after the lcd command is executed, the local working path of the client is displayed, while pwd displays the working path of the remote server. |
Create a directory on the server |
mkdir remote-directory |
The created directory can be a combination of letters, numbers, etc., but cannot be,? ,\,: and other special characters. |
Delete a directory on the server |
rmdir remote-directory |
- |
Display information about a specified directory or file on the server |
dir/ls [remote-filename [ local-filename] ] |
|
Delete the specified file on the server |
delete remote-filename |
- |
upload files |
put local-filename [remote-filename] |
- |
download file |
get remote-filename [local-filename] |
- |
Configure the data type of the transfer file to ASCII mode |
ascii |
pick one of two
|
Configure the data type of the transfer file to binary mode |
binary |
|
Configuration file transfer mode is passive mode |
passive |
pick one of two By default, the data transmission mode is active mode. |
Configuration file transfer mode is active mode |
undo passive |
|
View online help for FTP commands |
remotehelp [command] |
- |
Turn on the verbose switch |
verbose |
If the verbose switch is turned on, all FTP responses, including FTP protocol information, and detailed information returned by the FTP server will be displayed. |
- (Optional) Change login user
The device can log in to the FTP server with another user name without exiting the FTP client view. The FTP connection established is exactly the same as the FTP connection established by executing the ftp command.
Steps |
Order |
illustrate |
In FTP client view, change the current login user |
user user-name [ password ] |
After changing the current login user, the connection between the original user and the server will be disconnected. |
- Disconnect from FTP server
Users can select different commands in the FTP client view to disconnect from the FTP server.
Steps |
Order |
illustrate |
Terminate the connection to the server and return to user view |
bye or quit |
pick one of two. |
Terminate the connection to the server and fall back to FTP client view |
File operations close or disconnect via FTP
|