bash 无法登录到 ftp 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/13606649/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cannot login to the ftp server
提问by Smithis
Anyone has an idea what will be the problem?
任何人都知道会出现什么问题?
#!/bin/bash -x
HOST='192.163.3.3'
USER='ftpuser'
PASSWD='apple'
Logfile=a.log
while :; do
ftp -n -p -v $HOST < example.script >> a.log
grep -qF "Connected" a.log &&
grep -qF "File successfully transferred" a.log && break
done
quote USER $USER
quote PASS $PASSWD
example.script contains
example.script 包含
 put example.txt
after running it gives
运行后它给出
 grep: a.log: No such file or directory
 grep: a.log: No such file or directory
                .
                .
example.script and the created a.log is on /home directory
example.script 和创建的 a.log 位于 /home 目录
the a.log contains
a.log 包含
 Connected to 192.163.3.3.
 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
 220-You are user number 9 of 50 allowed.
 220-Local time is now 14:38. Server port: 21.
 220-This is a private system - No anonymous login
 220-IPv6 connections are also welcome on this server.
 220 You will be disconnected after 15 minutes of inactivity.
 Remote system type is UNIX.
 Using binary mode to transfer files.
 local: example.txt remote: example.txt
 530 You aren't logged in
 Passive mode refused.
 221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
 221 Logout.
why cant i logged in?
为什么我不能登录?
  HOST='192.163.3.3'
  USER='ftpuser'
  PASSWD='apple'
  FILE='example.txt'
  Logfile=a.log
  ftp -n -p -v $HOST << SCRIPT_END >> a.log
  quote USER $USER
  quote PASS $PASSWD
  put $FILE
  SCRIPT_END
with this it works but why? what will be the difference?
有了这个它可以工作,但为什么呢?有什么区别?
回答by Hyperlisk
Your FTP daemon is refusing passive mode file transfers (PASV command). You have to enable passive mode transfers on Pure-FTPd. This site has nice tutorial on how to do it: Getting passive FTP connections to work through a firewall properly- scroll down to section Setting up the FTP Server (Pure-FTPD).
您的 FTP 守护进程拒绝被动模式文件传输(PASV 命令)。您必须在 Pure-FTPd 上启用被动模式传输。这个站点有关于如何做到这一点的很好的教程: 让被动 FTP 连接正确地通过防火墙工作- 向下滚动到设置 FTP 服务器 (Pure-FTPD) 部分。
回答by Michael Ballent
It is complaining about being in passive mode, I would remove the -p from the command or allow passive FTP.
它抱怨处于被动模式,我会从命令中删除 -p 或允许被动 FTP。
-p Use passive mode for data transfers. Allows use of ftp in environments where a firewall prevents connections from the outside world back to the client machine. Requires that the ftp server support the PASV command. This is the default now for all clients (ftp and pftp) due to security concerns using the PORT transfer mode. The flag is kept for compatibility only and has no effect anymore.
-p 使用被动模式进行数据传输。允许在防火墙阻止从外部世界连接回客户端计算机的环境中使用 ftp。要求 ftp 服务器支持 PASV 命令。由于使用 PORT 传输模式的安全问题,这是现在所有客户端(ftp 和 pftp)的默认设置。该标志仅用于兼容性目的,不再有效。
回答by David W.
I usually find creating a netrcfile and using that to at least start my FTP session gets me around a lot of issues with scripting an ftp session. Most ftp programs give you the option of using an alternate netrcfile, so you don't need to setup one at $HOME/.netrc.
我通常会发现创建一个netrc文件并使用它至少启动我的 FTP 会话让我解决了编写 ftp 会话脚本的很多问题。大多数 ftp 程序都为您提供了使用备用netrc文件的选项,因此您无需在$HOME/.netrc.
I believe you just need a one liner like this:
我相信你只需要一个这样的衬垫:
machine 192.163.3.3 login ftpuser password apple
Unfortunately, I can't test it because I don't have ftp setup anywhere. Everything here is scp/ssh/sftp. Here's an example.netrcfile.
不幸的是,我无法测试它,因为我在任何地方都没有 ftp 设置。这里的一切都是scp/ ssh/ sftp。这是一个示例.netrc文件。

