特定的FTP连接无法上传文件

我已经在服务器上安装了vsftpd。 添加了一个新的ftp组,并创build了一个用户并添加到该组中。

我testing了3个不同的场景,其中只有一个正常工作,另外两个给我FAIL UPLOAD / 425无法build立连接

情况1:

  • 使用FileZilla从我的电脑连接
  • 我得到的文件列表,可以上传/下载任何文件。

正如你所看到的,服务器说:“进入被动模式”,并发送他的公共IP,并使用我在configuration文件中设置的端口范围:

Jun 5 19:09:36 zhny vsftpd[1]: [ftpuser] OK LOGIN: Client "xxx.xxx.xxx.xxx" Jun 5 19:09:36 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "230 Login successful." Jun 5 19:09:37 zhny vsftpd[1]: [ftpuser] FTP command: Client "xxx.xxx.xxx.xxx", "SYST" Jun 5 19:09:37 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "215 UNIX Type: L8" Jun 5 19:09:37 zhny vsftpd[1]: [ftpuser] FTP command: Client "xxx.xxx.xxx.xxx", "FEAT" Jun 5 19:09:37 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "211-Features:" Jun 5 19:09:37 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", " EPRT#015#012" Jun 5 19:09:37 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", " EPSV#015#012" Jun 5 19:09:37 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", " MDTM#015#012" Jun 5 19:09:37 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", " PASV#015#012" Jun 5 19:09:37 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", " REST STREAM#015#012" Jun 5 19:09:37 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", " SIZE#015#012" Jun 5 19:09:37 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", " TVFS#015#012" Jun 5 19:09:37 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", " UTF8#015#012" Jun 5 19:09:37 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "211 End" Jun 5 19:09:38 zhny vsftpd[1]: [ftpuser] FTP command: Client "xxx.xxx.xxx.xxx", "OPTS UTF8 ON" Jun 5 19:09:38 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "200 Always in UTF8 mode." Jun 5 19:09:38 zhny vsftpd[1]: [ftpuser] FTP command: Client "xxx.xxx.xxx.xxx", "PWD" Jun 5 19:09:38 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "257 "/srv/ftpvs/ftpuser"" Jun 5 19:09:39 zhny vsftpd[1]: [ftpuser] FTP command: Client "xxx.xxx.xxx.xxx", "TYPE I" Jun 5 19:09:39 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "200 Switching to Binary mode." Jun 5 19:09:39 zhny vsftpd[1]: [ftpuser] FTP command: Client "xxx.xxx.xxx.xxx", "PASV" Jun 5 19:09:39 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "227 Entering Passive Mode (zzz,zz,zzz,zzz,66,108)." Jun 5 19:09:40 zhny vsftpd[1]: [ftpuser] FTP command: Client "xxx.xxx.xxx.xxx", "LIST" Jun 5 19:09:40 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "150 Here comes the directory listing." Jun 5 19:09:41 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "226 Directory send OK." 

情景2:

  • 通过与我的电脑相同的networking中的服务器的命令行连接
  • 连接很好,但是当我做一个“ls”来获取文件列表,我得到一个错误。

正如你所看到的,服务器在说“考虑使用pasv”而不是发送他自己的IP。 在上一行中,似乎客户端正在发送他的IP,而FileZilla客户端没有发生这种情况:

 Jun 5 19:14:43 zhny vsftpd[1]: [ftpuser] OK LOGIN: Client "xxx.xxx.xxx.xxx" Jun 5 19:14:44 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "230 Login successful." Jun 5 19:14:44 zhny vsftpd[1]: [ftpuser] FTP command: Client "xxx.xxx.xxx.xxx", "SYST" Jun 5 19:14:44 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "215 UNIX Type: L8" Jun 5 19:14:48 zhny vsftpd[1]: [ftpuser] FTP command: Client "xxx.xxx.xxx.xxx", "PORT xxx,xxx,xxx,xxx,205,157" Jun 5 19:14:48 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "200 PORT command successful. Consider using PASV." Jun 5 19:14:49 zhny vsftpd[1]: [ftpuser] FTP command: Client "xxx.xxx.xxx.xxx", "LIST" Jun 5 19:15:49 zhny vsftpd[1]: [ftpuser] FTP response: Client "xxx.xxx.xxx.xxx", "425 Failed to establish connection." 

情景3:

  • 从必须将数据发送到FTP的设备连接。
  • 连接进行的很好,但是当它试图放入一个文件时,ftp会发送FAIL UPLOAD错误信息
  • 与情况2相同的行为(说“考虑使用pasv”和客户端发送他的IP)

最后,您可以看到FAIL UPLOAD消息,并发送了0KB:

 Jun 5 14:51:46 zhny vsftpd[1]: [ftpuser] OK LOGIN: Client "yyy.yyy.y.yy" Jun 5 14:51:46 zhny vsftpd[1]: [ftpuser] FTP response: Client "yyy.yyy.y.yy", "230 Login successful." Jun 5 14:51:46 zhny vsftpd[1]: [ftpuser] FTP command: Client "yyy.yyy.y.yy", "TYPE I" Jun 5 14:51:46 zhny vsftpd[1]: [ftpuser] FTP response: Client "yyy.yyy.y.yy", "200 Switching to Binary mode." Jun 5 14:51:47 zhny vsftpd[1]: [ftpuser] FTP command: Client "yyy.yyy.y.yy", "PORT yyy,yyy,y,yy,244,168" Jun 5 14:51:47 zhny vsftpd[1]: [ftpuser] FTP response: Client "yyy.yyy.y.yy", "200 PORT command successful. Consider using PASV." Jun 5 14:51:48 zhny vsftpd[1]: [ftpuser] FTP command: Client "yyy.yyy.y.yy", "STOR TZE_1MIN_20130605_145200.dat" Jun 5 14:51:54 zhny vsftpd[1]: [ftpuser] OK LOGIN: Client "yyy.yyy.y.yy" Jun 5 14:51:54 zhny vsftpd[1]: [ftpuser] FTP response: Client "yyy.yyy.y.yy", "230 Login successful." Jun 5 14:51:55 zhny vsftpd[1]: [ftpuser] FTP command: Client "yyy.yyy.y.yy", "TYPE I" Jun 5 14:51:55 zhny vsftpd[1]: [ftpuser] FTP response: Client "yyy.yyy.y.yy", "200 Switching to Binary mode." Jun 5 14:51:55 zhny vsftpd[1]: [ftpuser] FTP command: Client "yyy.yyy.y.yy", "PORT yyy,yyy,y,yy,244,169" Jun 5 14:51:55 zhny vsftpd[1]: [ftpuser] FTP response: Client "yyy.yyy.y.yy", "200 PORT command successful. Consider using PASV." Jun 5 14:51:56 zhny vsftpd[1]: [ftpuser] FTP command: Client "yyy.yyy.y.yy", "STOR TZE_1MIN_20130605_135200.dat" Jun 5 14:52:48 zhny vsftpd[1]: [ftpuser] FTP response: Client "yyy.yyy.y.yy", "425 Failed to establish connection." Jun 5 14:52:48 zhny vsftpd[1]: [ftpuser] FAIL UPLOAD: Client "yyy.yyy.y.yy", "/srv/ftpvs/ftpuser/TZE_1MIN_20130605_145200.dat", 0.00Kbyte/sec Jun 5 14:52:56 zhny vsftpd[1]: [ftpuser] FTP response: Client "yyy.yyy.y.yy", "425 Failed to establish connection." Jun 5 14:52:56 zhny vsftpd[1]: [ftpuser] FAIL UPLOAD: Client "yyy.yyy.y.yy", "/srv/ftpvs/ftpuser/TZE_1MIN_20130605_135200.dat", 0.00Kbyte/sec 

在这里你有我的vsftpd.conf文件:

 anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES xferlog_enable=YES log_ftp_protocol=YES syslog_enable=YES connect_from_port_20=YES idle_session_timeout=300 data_connection_timeout=300 listen=YES pam_service_name=vsftpd tcp_wrappers=YES chroot_local_user=YES chroot_list_enable=YES pasv_min_port=17000 pasv_max_port=17005 pasv_address=ip_of_the_ftp_server 

在vsftpd.chroot_list文件中,我只为我为ftp创build的用户创build了1行。

唯一的区别是我可以看到不同的情况是,使用FileZilla的FTP是使用PASV连接。 可能是这个工作不正常的原因?

任何其他的想法和build议,欢迎。

当客户端和服务器之间存在NAT系统或未configurationFTP的防火墙时,这是FTP相当常见的问题。

您的第一个样本使用所谓的“被动模式”FTP,而另外两个样本使用“主动模式”。

FTP通过两种不同的TCP连接工作:一个用于传输简单命令(login,列表目录等)的命令通道(在端口21上)和一个用于发送任何数据的数据通道(即:文件但是也是目录列表请求的结果)。

在主动模式下,当传输文件或目录列表时,客户端将指定要使用的IP地址和端口号(PORT命令),服务器将build立端口20到指定连接的新连接。 如果客户端位于防火墙或NAT设备之后,将阻止该连接成功。

在被动模式下,数据通道打开方向相反:客户端将发送PASV命令,服务器将开始侦听随机空闲端口(通常在dynamic范围内),并通知客户端连接到该端口。

被动模式的使用更为普遍,因为在服务器上或靠近服务器的防火墙相对容易检测命令并允许新的连接。 另一方面,主动模式连接要求客户端能够接受来自服务器的连接,并且在NAT设备或公司防火墙后通常不能很好地工作。

该解决scheme通常是完全禁用服务器上的主动模式,或者确保客户端都使用被动模式。 现代客户端(全部默认为主动模式)通常不会出现问题,但可能是旧的或FTP脚本的问题。