FTP协议
FTP 的独特的优势同时也是与其它客户服务器程序最大的不同点就在于它在两台通信的主机之间使用了两条 TCP 连接,一条是数据连接,用于数据传送;另一条是控制连接,用于传送控制信息(命令和响应),这种将命令和数据分开传送的思想大大提高了 FTP 的效率,而其它客户服务器应用程序一般只有一条 TCP 连接。在整个交互的 FTP 会话中,控制连接始终是处于连接状态的,数据连接则在每一次文件传送时先打开后关闭
FTP客户端项目
实现功能:
登录
pwd
cd
mkdir
rmdir
delete
bye
ls
put
get
注意:发送的命令要以'\n'结尾,否则服务器无法识别文章来源:https://www.toymoban.com/news/detail-689279.html
// 登录
[15:06:06] [R] 正在连接到 47.97.229.46 -> IP=47.97.229.46 PORT=21
[15:06:06] [R] 已连接到 47.97.229.46
[15:06:06] [R] 220 (vsFTPd 3.0.2)
// 发送用户名
[15:06:06] [R] USER student
[15:06:06] [R] 331 Please specify the password.
// 发送密码
[15:06:06] [R] PASS (hidden)
[15:06:06] [R] 230 Login successful.
[15:06:06] [R] OPTS UTF8 ON
[15:06:06] [R] 200 Always in UTF8 mode.
// pwd
[15:06:06] [R] PWD
[15:06:06] [R] 257 "/home/student"
// ls
// 开启PASV数据通道
[15:06:06] [R] PASV
[15:06:06] [R] 227 Entering Passive Mode (172,16,83,85,89,59).
[15:06:06] [R] 正在打开数据连接 IP: 47.97.229.46 端口: 22843
[15:06:06] [R] LIST -al
[15:06:06] [R] 150 Here comes the directory listing.
[15:06:06] [R] 226 Directory send OK.
// cd
[15:06:15] [R] CWD C++2307-1
[15:06:15] [R] 250 Directory successfully changed.
// mkdir
[15:06:30] [R] MKD dir
[15:06:30] [R] 257 "/home/student/C++2307-1/dir" created
// rmdir
[15:06:41] [R] RMD dir
[15:06:41] [R] 250 Remove directory operation successful.
[15:07:36] [R] TYPE A
[15:07:36] [R] 200 Switching to ASCII mode.
[15:07:36] [R] SIZE network.h
[15:07:36] [R] 213 913
[15:07:36] [R] MDTM network.h
[15:07:36] [R] 213 20230811033936
// get
[15:07:36] [R] PASV
[15:07:36] [R] 227 Entering Passive Mode (172,16,83,85,97,119).
[15:07:36] [R] 正在打开数据连接 IP: 47.97.229.46 端口: 24951
[15:07:36] [R] RETR network.h
[15:07:36] [R] 150 Opening BINARY mode data connection for network.h (913 bytes).
[15:07:36] [R] 226 Transfer complete.
// put
[15:08:00] [R] PASV
[15:08:00] [R] 227 Entering Passive Mode (172,16,83,85,39,64).
[15:08:00] [R] 正在打开数据连接 IP: 47.97.229.46 端口: 10048
[15:08:00] [R] STOR Linux环境编程day01.c
[15:08:00] [R] 150 Ok to send data.
[15:08:00] [R] 226 Transfer complete.
[15:08:00] [R] MDTM 20230731085722 /home/student/Linux环境编程day01.c
[15:08:00] [R] 213 File modification time set.
// delete 文件
[15:08:15] [R] DELE Linux环境编程day01.c
[15:08:15] [R] 250 Delete operation successful.
[15:08:15] 已删除 1 个文件 和 0 个文件夹 (11 KB) 耗时 0.03 秒
// 上传 断点续传
[17:05:52] [R] TYPE I
[17:05:52] [R] 200 Switching to Binary mode.
[17:05:52] [R] SIZE 20221203_134016.mp4
[17:05:52] [R] 550 Could not get file size.
[17:05:52] [R] PASV
[17:05:52] [R] 227 Entering Passive Mode (172,16,83,85,80,71).
[17:05:52] [R] 正在打开数据连接 IP: 47.97.229.46 端口: 20551
[17:05:52] [R] STOR 20221203_134016.mp4
[17:05:52] [R] 150 Ok to send data.
[17:05:57] (软中止 - 发送“ABOR”命令)
[17:05:57] [R] 226 Transfer complete.
[17:05:57] [R] QUIT
[17:05:57] [R] 传输失败: 20221203_134016.mp4
[17:05:57] [R] 已注销: 47.97.229.46 (持续时间: 54 秒)
[17:05:57] 已传输 0 个文件 (0 字节) 耗时 5 秒 (0.0 KB/s)
[17:05:57] 已被用户中止
// 续传
[17:06:51] [R] TYPE I
[17:06:51] [R] 200 Switching to Binary mode.
[17:06:51] [R] SIZE 20221203_134016.mp4
[17:06:51] [R] 213 26083328
[17:06:51] [R] MDTM 20221203_134016.mp4
[17:06:51] [R] 213 20230814090557
[17:06:51] [R] PASV
[17:06:51] [R] 227 Entering Passive Mode (172,16,83,85,132,250).
[17:06:51] [R] 正在打开数据连接 IP: 47.97.229.46 端口: 34042
[17:06:51] [R] REST 26083328
[17:06:51] [R] 350 Restart position accepted (26083328).
[17:06:51] [R] STOR 20221203_134016.mp4
[17:06:51] [R] 150 Ok to send data.
[17:07:03] (软中止 - 发送“ABOR”命令)
[17:07:03] [R] 226 Transfer complete.
[17:07:04] [R] 传输失败: 20221203_134016.mp4 (50.63 MB / 415.36 MB) 耗时 11 秒 (4.47 MB/s)
[17:07:04] 已传输 0 个文件 (0 字节) 耗时 12 秒 (0.0 KB/s)
[17:07:04] 已被用户中止
[17:07:10] [R] PASV
[17:07:10] [R] 227 Entering Passive Mode (172,16,83,85,153,212).
[17:07:10] [R] 正在打开数据连接 IP: 47.97.229.46 端口: 39380
[17:07:10] [R] LIST -al
[17:07:10] [R] 150 Here comes the directory listing.
[17:07:10] [R] 226 Directory send OK.
[17:07:10] [R] 列表完成: 1 KB 耗时 0.06 秒 (1.9 KB/s)
[17:07:14] [R] SIZE 20221203_134016.mp4
[17:07:14] [R] 213 79167488
[17:07:14] [R] MDTM 20221203_134016.mp4
[17:07:14] [R] 213 20230814090704
[17:07:14] [R] PASV
[17:07:14] [R] 227 Entering Passive Mode (172,16,83,85,134,255).
[17:07:14] [R] 正在打开数据连接 IP: 47.97.229.46 端口: 34559
[17:07:14] [R] REST 79167488
[17:07:14] [R] 350 Restart position accepted (79167488).
[17:07:14] [R] STOR 20221203_134016.mp4
[17:07:14] [R] 150 Ok to send data.
[17:07:23] (软中止 - 发送“ABOR”命令)
[17:07:23] [R] 226 Transfer complete.
[17:07:24] [R] 传输失败: 20221203_134016.mp4 (42.13 MB / 415.36 MB) 耗时 9 秒 (4.65 MB/s)
[17:07:24] 已传输 0 个文件 (0 字节) 耗时 10 秒 (0.0 KB/s)
[17:07:24] 已被用户中止
ftp客户端项目 (gitee)文章来源地址https://www.toymoban.com/news/detail-689279.html
到了这里,关于网络编程day3-FTP客户端项目的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!