1. 检查并启动SSH服务(SFTP必需)
 FileZilla使用SFTP协议时,依赖服务器的SSH服务(openssh-server)。若未安装或未运行,会导致连接被拒绝。
sudo apt update && sudo apt install openssh-server,完成安装。sudo systemctl start ssh启动服务;为确保开机自启,执行sudo systemctl enable ssh。sudo systemctl status ssh,若显示“active (running)”则表示服务正常。2. 检查服务器防火墙设置
 Ubuntu默认使用ufw防火墙,若未允许SSH(端口22)或FTP(端口21)流量,会拦截连接。
sudo ufw allow ssh(或sudo ufw allow 22/tcp),允许SSH连接。sudo ufw allow 21/tcp,允许FTP控制端口;若使用被动模式,还需开放被动端口范围(如sudo ufw allow 60000:61000/tcp)。sudo ufw status,确认列表中包含上述允许规则。3. 确认SSH监听端口正确
 若服务器修改了SSH默认端口(22),需确保FileZilla配置的端口与服务器一致。
sudo ss -tlpn | grep sshd,输出中“Local Address”显示的端口(如0.0.0.0:22)即为当前端口。4. 检查FileZilla客户端配置
 FileZilla配置错误(如协议选错、IP/端口/用户名错误)是常见原因。
5. 测试命令行连接(排除FileZilla自身问题)
 在客户端终端执行以下命令,测试是否能连接服务器:
sftp username@server_ip(若使用非默认端口,添加-P port,如sftp -P 2222 username@server_ip)。ftp server_ip(输入用户名密码后,执行ls命令验证连接)。6. 调整被动模式设置(FTP协议专用)
 若使用FTP协议且连接被拒绝,可能是被动模式(PASV)的端口范围未开放或配置错误。
/etc/vsftpd.conf,添加或修改以下行:pasv_enable=YES pasv_min_port=60000 pasv_max_port=61000 pasv_min_port和pasv_max_port为被动模式端口范围,需与服务器防火墙开放范围一致)。sudo systemctl restart vsftpd使配置生效。7. 检查用户权限与目录权限
 若用户无权限访问目标目录,会导致连接后无法上传/下载。
sudo useradd -m ftpuser && sudo passwd ftpuser。/home/ftpuser,执行sudo chmod 755 /home/ftpuser,允许用户读写该目录。