我目前正在努力解决 vsftpd 的某种连接问题。
我使用的是 arch linux 并安装了 vsftpd 版本 3.0.3。
我不使用 iptables 或任何东西。当我连接到 FTP 服务器时,我可以成功登录并浏览目录。我还可以上传和下载文件。
FTP 用户被chroot 到其主目录中,并且所有子目录都归ftp 用户所有。
目前的结构:
|- home_dir
|- dir1
|- dir2
|- dir3
|- dir3
|- dir4
|- ...
我可以“cd”进入 dir1,执行“ls”并上传/下载文件。我也可以“cd”到 dir2,但棘手的部分来了:
我可以完美地将文件上传到 dir2,但是当我执行“ls”时,服务器正在关闭连接,并显示:“421 服务不可用,远程服务器已关闭连接”。我发现,原因是“dir2”的几个子目录。我发现,所有子目录中 8 个的存在导致连接被关闭。一旦我删除它们,列表就可以正常工作。所有名称均包含从 a 到 z 的小写字母,没有特殊字符。
我的 ftp 配置:
log_ftp_protocol=YES
anonymous_enable=NO
userlist_enable=YES
userlist_file=/etc/vsftpd.user_list
userlist_deny=NO
pasv_addr_resolve=YES
pasv_address=mydomain.com
pasv_enable=Yes
pasv_min_port=40020
pasv_max_port=40030
local_enable=YES
write_enable=YES
local_umask=002
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
chown_uploads=YES
chown_username=myuser
ftpd_banner=Welcome.
chroot_local_user=YES
这就是服务器 FTP-Log 所说的:
Wed Dec 28 13:55:06 2016 [pid 2] CONNECT: Client "<client_ip>"
Wed Dec 28 13:55:06 2016 [pid 2] FTP response: Client "<client_ip>", "220 Welcome."
Wed Dec 28 13:55:07 2016 [pid 2] FTP command: Client "<client_ip>", "USER myuser"
Wed Dec 28 13:55:07 2016 [pid 2] [myuser] FTP response: Client "<client_ip>", "331 Please specify the password."
Wed Dec 28 13:55:07 2016 [pid 2] [myuser] FTP command: Client "<client_ip>", "PASS <password>"
Wed Dec 28 13:55:07 2016 [pid 1] [myuser] OK LOGIN: Client "<client_ip>"
Wed Dec 28 13:55:07 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "230 Login successful."
Wed Dec 28 13:55:07 2016 [pid 3] [myuser] FTP command: Client "<client_ip>", "OPTS UTF8 ON"
Wed Dec 28 13:55:07 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "200 Always in UTF8 mode."
Wed Dec 28 13:55:07 2016 [pid 3] [myuser] FTP command: Client "<client_ip>", "PWD"
Wed Dec 28 13:55:07 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "257 "/" is the current directory"
Wed Dec 28 13:55:07 2016 [pid 3] [myuser] FTP command: Client "<client_ip>", "TYPE I"
Wed Dec 28 13:55:07 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "200 Switching to Binary mode."
Wed Dec 28 13:55:07 2016 [pid 3] [myuser] FTP command: Client "<client_ip>", "PASV"
Wed Dec 28 13:55:07 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "227 Entering Passive Mode (<server_ip>,156,86)."
Wed Dec 28 13:55:07 2016 [pid 3] [myuser] FTP command: Client "<client_ip>", "LIST"
Wed Dec 28 13:55:07 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "150 Here comes the directory listing."
Wed Dec 28 13:55:08 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "226 Directory send OK."
Wed Dec 28 13:55:09 2016 [pid 3] [myuser] FTP command: Client "<client_ip>", "CWD /dir1"
Wed Dec 28 13:55:09 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "250 Directory successfully changed."
Wed Dec 28 13:55:09 2016 [pid 3] [myuser] FTP command: Client "<client_ip>", "PASV"
Wed Dec 28 13:55:09 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "227 Entering Passive Mode (<server_ip>,156,92)."
Wed Dec 28 13:55:09 2016 [pid 3] [myuser] FTP command: Client "<client_ip>", "LIST"
Wed Dec 28 13:55:09 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "150 Here comes the directory listing."
Wed Dec 28 13:55:09 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "226 Directory send OK."
Wed Dec 28 13:55:11 2016 [pid 3] [myuser] FTP command: Client "<client_ip>", "CWD /dir1/dir2"
Wed Dec 28 13:55:11 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "250 Directory successfully changed."
Wed Dec 28 13:55:11 2016 [pid 3] [myuser] FTP command: Client "<client_ip>", "PASV"
Wed Dec 28 13:55:11 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "227 Entering Passive Mode (<server_ip>,156,87)."
Wed Dec 28 13:55:11 2016 [pid 3] [myuser] FTP command: Client "<client_ip>", "LIST"
Wed Dec 28 13:55:11 2016 [pid 3] [myuser] FTP response: Client "<client_ip>", "150 Here comes the directory listing."
日志始终在“150 Here comes the Directory Listing.”之后停止。我试了几次。
当我在终端上使用 ftp 命令时,我看到的是:
$ ftp -n 127.0.0.1
Connected to 127.0.0.1.
220 Welcome.
ftp> user myuser
331 Please specify the password.
Password:
230 Login successful.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x 4 1000 1000 4096 Dec 28 13:27 dir1
226 Directory send OK.
ftp> cd dir1
250 Directory successfully changed.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rwxr-xr-x 1 1000 1000 469504 Dec 23 03:03 file_1
-rw-r--r-- 1 1000 1000 186 Feb 19 2016 file_2
-rw-r--r-- 1 1000 1000 121856 Dec 23 00:16 file_3
-rw-r--r-- 1 1000 1000 118272 Feb 12 2016 file_4
-rw-r--r-- 1 1000 1000 88232 Mar 22 2016 file_5
-rw-r--r-- 1 1000 1000 64680 Mar 22 2016 file_6
-rw-r--r-- 1 1000 1000 101032 Mar 22 2016 file_7
-rw-r--r-- 1 1000 1000 6144 Mar 22 2016 file_8
-rw-r--r-- 1 1000 1000 899584 Mar 22 2016 file_9
drwxrwxr-x 42 1000 1000 4096 Dec 28 11:38 dir2
226 Directory send OK.
ftp> cd dir2
250 Directory successfully changed.
ftp> pwd
257 "/dir1/dir2" is the current directory
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
421 Service not available, remote server has closed connection
非常感谢您的帮助。
答案1
答案2
我也遇到了完全相同的问题,也是在带有 vsftp 3.0.3 (pkg rel 3) 的 Arch Linux 上。事实证明,导致此行为的目录中的文件过多 (2,666)。删除其中大部分后,通过 ftp 列出的列表再次开始工作。
很奇怪吧? 2,666 看起来并不算太多。但我确实没有改变任何其他事情。 vsftp 设置仍然相同,文件系统权限未受影响。此外,文件名不包含任何奇怪的字符(长度最多为 21 个字符的连续数字)。