![使用 ftp 的配置文件并在初始连接时启用自动登录](https://linux22.com/image/20196/%E4%BD%BF%E7%94%A8%20ftp%20%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E5%B9%B6%E5%9C%A8%E5%88%9D%E5%A7%8B%E8%BF%9E%E6%8E%A5%E6%97%B6%E5%90%AF%E7%94%A8%E8%87%AA%E5%8A%A8%E7%99%BB%E5%BD%95.png)
我想像在 SSH 中一样,您可以将服务器保存在配置文件中。我还想保存我的用户名和密码,这样每次连接时就不会提示。我使用 ftp 命令,
答案1
从man ftp
我的 CentOS 上
If auto-login is enabled, ftp will check the .netrc (see below)
file in the user’s home directory for an entry describing an account on the remote machine. If no entry exists, ftp will prompt for the
remote machine login name (default is the user identity on the local machine), and, if necessary, prompt for a password and an account
with which to login.
示例:~/.netrc
machine ftp.freebsd.org
login anonymous
password [email protected]
machine myownmachine
login useraccount
password xyz
手册页中有关 .netrc 文件的更多信息:
THE .netrc FILE
The .netrc file contains login and initialization information used by the auto-login process. It resides in the user’s home directory. The
following tokens are recognized; they may be separated by spaces, tabs, or new-lines:
machine name
Identify a remote machine name. The auto-login process searches the .netrc file for a machine token that matches the remote machine
specified on the ftp command line or as an open command argument. Once a match is made, the subsequent .netrc tokens are processed,
stopping when the end of file is reached or another machine or a default token is encountered.
default
This is the same as machine name except that default matches any name. There can be only one default token, and it must be after all
machine tokens. This is normally used as:
default login anonymous password user@site
thereby giving the user automatic anonymous ftp login to machines not specified in .netrc. This can be overridden by using the -n flag
to disable auto-login.
login name
Identify a user on the remote machine. If this token is present, the auto-login process will initiate a login using the specified name.
password string
Supply a password. If this token is present, the auto-login process will supply the specified string if the remote server requires a
password as part of the login process. Note that if this token is present in the .netrc file for any user other than anonymous, ftp will
abort the auto-login process if the .netrc is readable by anyone besides the user.
account string
Supply an additional account password. If this token is present, the auto-login process will supply the specified string if the remote
server requires an additional account password, or the auto-login process will initiate an ACCT command if it does not.