bash 使用具有多个帐户的 .netrc 连接到 ftp
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17088508/
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
Connect to ftp using .netrc with multiple accounts
提问by stratis
I have created a .netrcfile so i can have some macros and automatically make some standard operations inside my ftp server.
我已经创建了一个.netrc文件,因此我可以拥有一些宏并在我的 ftp 服务器中自动进行一些标准操作。
The problem is that now every time i connect to this machine it always connects with the same account automatically ,without giving me the option to select an account for this machine.
问题是现在每次我连接到这台机器时,它总是自动连接同一个帐户,而没有给我选择这台机器帐户的选项。
I found this question inside stackoverflow,but seems that there is no answer that can help me.
我在 stackoverflow 中发现了这个问题,但似乎没有可以帮助我的答案。
Thank you all in advance
谢谢大家
回答by David W.
In a .netrc file, each line referring to a particular machine looks like this:
在 .netrc 文件中,引用特定机器的每一行如下所示:
machine booster login baxter password swordfish
machine wooster login francis password sw0rdf1sh
This will define the logins for two machines: boosterand wooster. If you put in a line like this:
这将定义两台机器的登录名:booster和wooster。如果你输入这样的一行:
default login root password secret
This will be used for any other machines you haven't already listed.
这将用于您尚未列出的任何其他机器。
Macros can be defined for each machine, and are defined after the machineor defaultline. The macro is defined by the line macrofollowed by the macro name. If the name is init, that macro will be executed automatically by the system.
可以为每台机器定义宏,并在machine或default行之后定义。宏由macro后跟宏名称的行定义。如果名称为init,则该宏将由系统自动执行。
You need to define separate machinelines for each machine you are logging into, and then have a defaultline for all other machines (if so desired).
您需要为machine要登录的每台机器定义单独的行,然后default为所有其他机器定义一行(如果需要)。
You can also tell ftpnot to read in the .netrcfile by doing one of the following:
您还可以通过执行以下操作之一告诉ftp不要读入.netrc文件:
$ ftp -n
You can also use another net resourcefile besides the default .netrc:
除了默认的之外,您还可以使用另一个网络资源文件.netrc:
$ ftp -N my.netrc.file

