|
here 文档用来干嘛?
它主要将定义在它范围内的内容提交给交互式程序。这里演示一个使用 here 文档的使用实例,用来实现 FTP 文件的自动传输。命令如下:
$ ftp -i -v -n 121.15.145.7 <<END_FTP
user vh492377 123456
bin
cd www/bbs
put view.html
END_FTP 运行输出:Connected to 121.15.145.7 (121.15.145.7).
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 2 of 50 allowed.
220-Local time is now 11:11. Server port: 21.
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.
331 User vh492377 OK. Password required
230-User vh492377 has group access to: vh492377
230 OK. Current restricted directory is /
200 TYPE is now 8-bit binary
250 OK. Current directory is /www/bbs
local: view.html remote: view.html
227 Entering Passive Mode (121.15.145.7,176,210)
150 Accepted data connection
226-File successfully transferred
226 0.054 seconds (measured here), 1.87 Mbytes per second
105229 bytes sent in 0.0344 secs (3062.81 Kbytes/sec)
221-Goodbye. You uploaded 103 and downloaded 0 kbytes.
221 Logout. 在 ftp 命令中:
-i 选项表示关闭交互式信息提示。
-n 选项表示限制 ftp 的自动登录,即不使用。如果是自动登录,那么 ftp 不用你输入用户名,而会自动去查找 .netrc 文件来寻找用户名和密码,如果没找着,那么它仍然会提示你输入用户名和密码。所以这里要使用 -n 选项禁止使用自动登录功能。
-v 选项表示要输出详细的连接信息。
另外注意用户名和密码是通过 user 命令来录入的,即 user 后面跟着 用户名 和 密码。登录成功后,下面就是你要操作的 FTP 指令了。 |
|