1 @echo off
2 pem ftp 服务器
3 echo open 22.19.67.14>>temp.txt
4 pem user, password
5 echo user 123456 123456>>temp.txt
6 pem 执行的命令
7 echo rename test.txt moved/test.txt>>temp.txt
8 pem 关闭连接
9 echo bye>>temp.txt
10 ftp -n -s:temp.txt
11 del temp.txt
在本地通过测试后,非常高兴,于是我急忙对我的程序做了修改,发布。结果,FAILED!!!
with F*** word. 原来FTP的命令在windows和linux还是有点不一样的。Linux中FTP命令的选择项中没有-s:filename 这个项选择。有点小崩溃和无奈。继续google吧。 终于有了新的发现.Auto File Transfer Via FTP Batch Scripts In Both Windows And Linux。文章中提到通过修改用户根目录下的 .netrc
来实现。
machine 10.1.1.10
login walker-login-id-here
password walker-login-password-here
macdef init
prompt
mget *.*
quit
Leave one mandatory blank line here
Leave one mandatory blank line here
machine ftp.walkernews.net
login walker-login-id-here
password walker-login-password-here
macdef init
pwd
quit
Leave one mandatory blank line here Understand the .netrc file content
the keyword machine is used to specify the target ftp host that the ftp client connect to
the keyword login is used to specify the user login ID
the keyword password is used to specify the password used to authenticate the user login ID
the keyword macdef init is used to define the auto-ftp macro command that named as init (refer to man netrc for more information)
supposed the login authentication is successful, then the rest of lines after macdec init down to quit keyword are ftp client commands. The quit is identical to the byecommand.
after the quit keyword, press ENTER twice to leave two empty lines! These two lines are mandatory syntax of .netrc file for auto-ftp. As of this .netrc sample file, I’ve another ftp server added right after the first two empty lines, and end the second ftp server with another two empty lines as well.
然后再进行接下来的操作,chmod 600 .netrc 和 ftp ftp.walkernews.net 。太过于复杂了。如果对于FTP的操作比较固定,比如定期的上传同一文件夹下的文件到FTP上。不适合经常改变的命令和操作。搜索(不是陈凯歌的电影哦)继续。伟大的google无所不能。How to use ftp in a shell script。原来Linux下的FTP可以同ftp -n