bash 使用 wget 通过 FTP 下载目录,但不将密码作为参数传递
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5277991/
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
Using wget to download directories over FTP, but not passing the password as a parameter
提问by mattalxndr
When I don't have SSH access to a server, I usually download stuff over FTP, like this:
当我无法通过 SSH 访问服务器时,我通常通过 FTP 下载内容,如下所示:
wget -r ftp://user:pass@server/path/to/dir
How do I keep my password more secure? I don't like that the password is in the command, but when I try something like this:
如何让我的密码更安全?我不喜欢密码在命令中,但是当我尝试这样的事情时:
wget -r ftp://user@server/path/to/dir
it doesn't work. It gives me "Login incorrect".
它不起作用。它给我“登录不正确”。
回答by mattalxndr
This also does the trick:
这也可以解决问题:
wget -r --ask-password ftp://user@server/path/to/dir
ask_password = on/offcan also be declared in your ~/.wgetrc.
ask_password = on/off也可以在您的~/.wgetrc.
回答by Martin
You can put your credentials in ~/.wgetrclike so:
您可以~/.wgetrc像这样输入您的凭据:
ftp_user = user
ftp_password = pass
Depending on your needs, it is also possible to use a different locationfor this configuration file:
根据您的需要,也可以为此配置文件使用不同的位置:
When initializing, Wget will look for a global startup file, /usr/local/etc/wgetrc by default (or some prefix other than /usr/local, if Wget was not installed there) and read commands from there, if it exists.
Then it will look for the user's file. If the environmental variable WGETRC is set, Wget will try to load that file. Failing that, no further attempts will be made.
If WGETRC is not set, Wget will try to load $HOME/.wgetrc.
初始化时,Wget 将查找全局启动文件,默认情况下 /usr/local/etc/wgetrc(或 /usr/local 以外的一些前缀,如果 Wget 没有安装在那里)并从那里读取命令,如果它存在。
然后它将查找用户的文件。如果设置了环境变量 WGETRC,Wget 将尝试加载该文件。否则,将不会进行进一步的尝试。
如果未设置 WGETRC,Wget 将尝试加载 $HOME/.wgetrc。

