perl 处理ftp 下 命令问题

perl 处理ftp 下 命令问题

请问:
如果希望用Perl程序输入这样的命令行到ftp的提示符下,如何做?
cd 'ndevfns.icmvr.FNETBTCH.COB'
lcd /home/fnsap3i/bancs/day/FNETBTCH.COB
mput *
here doc会吧:
my $cmd = q{
  ftp -n -v $mainframe_host <<EOF >> $your_log 2>&1
  quote USER $user
  quote PASS $pass
  cd 'ndevfns.icmvr.FNETBTCH.COB'
  lcd /home/fnsap3i/bancs/day/FNETBTCH.COB
  mput *
  quit
  EOF
};
print `$cmd`;

另外, Expect也是可以的.
能再详细点解释一下么?
$cmd = q{}
这个q是啥意思啊?

quote USER $user
这句里面 USER 是关键字么?

最后是用system ($cmd) 来运行这一对命令么?

开头说的here doc 是啥意思? 不懂。

菜, 烦请指点指点
1.
q//之类的同'', 字符串中已有'和/就换了个q{}.

2.
Here Documents是shell中的概念, 用来重定向输入:
<<word就表示Here Documents开始, 直到遇到word(不包括行首空格);

3. ftp关键字

4. system只返回shell中命令的exit code: ftp运行成功了, 即使文件/目录不存在, 也是返回成功(0)的.
   ``返回命令的stdout, 这样可以看到具体的过程
ftp -n -v $mainframe_host
  quote USER $user
  quote PASS $pass

上面这块儿还是不太明白:
-n -v 都代表什么意思??
quote USER $user  这句quote USER 是啥意思啊?? $user  应该是真正的用户名

我把$user 替换成我的用户名, 然后下面的$pass 替换成密码

不对,连不上服务器
得到的log内容为:
Not connected.
Not connected.
Not connected.
Not connected.

烦请再解释解释??多谢了。
man ftp看看就知道了

特地找了个ftp: ftp.mozilla.org
user: anonymous
pass: (空)
#!/usr/perl/bin

$mvs = "22.6.57.76" ;

#$user = "abcdefg" ;
#$pass = "1234567" ;

$user = "anonymous" ;
$pass = "" ;

my $cmd = q{
  ftp -n -v $mvs <<EOD_LINE
  quote USER $user
  quote PASS $pass
  cd 'fnsap3i.ap3ii9br.day.FNETBTCH.CNTL'
  lcd /home/pvcsbjj/bancs
  mput *
  quit
EOD_LINE


} ;

print `$cmd` ;
print "End\n" ;
这个程序在UNIX下执行得到以下结果:
Not connected.
Not connected.
Not connected.
Local directory now /home/pvcsbjj/bancs
Not connected.
End

在windows下执行得到以下结果:
D:\BJJ_Doc\Perl>perl t_ftp.pl
End
似乎在Windows下, ftp那几条命令根本就没起作用啊,至少本地路径根本不对都没有报错


QUOTE:
原帖由 hoohoobjj 于 2008-1-13 21:22 发表
#!/usr/perl/bin

$mvs = "22.6.57.76" ;

#$user = "abcdefg" ;
#$pass = "1234567" ;

$user = "anonymous" ;
$pass = "" ;

my $cmd = q{
  ftp -n -v $mvs  

1. 你的server该用什么user就用什么user
    人家ftp.mozilla.org是支持匿名登陆的, 下为xp上ftp交互模式匿名登陆:
ftp -n ftp.mozilla.org
Connected to dm-ftp01.mozilla.org.
220-
220-   ftp.mozilla.org / archive.mozilla.org - files are in /pub/mozilla.org
220-
220-   Notice: This server is the only place to obtain nightly builds and needs to
220-   remain available to developers and testers. High bandwidth servers that
220-   contain the public release files are available at ftp://releases.mozilla.org/
220-   If you need to link to a public release, please link to the release server,
220-   not here. Thanks!
220-
220-   Attempts to download high traffic release files from this server will get a
220-   "550 Permission denied." response.
220
ftp> quote USER anonymous
331 Please specify the password.
ftp> quote PASS
230-
230-   ftp.mozilla.org / archive.mozilla.org - files are in /pub/mozilla.org
230-
230-   Notice: This server is the only place to obtain nightly builds and needs to
230-   remain available to developers and testers. High bandwidth servers that
230-   contain the public release files are available at ftp://releases.mozilla.org/
230-   If you need to link to a public release, please link to the release server,
230-   not here. Thanks!
230-
230-   Attempts to download high traffic release files from this server will get a
230-   "550 Permission denied." response.
230 Login successful.
ftp> quit


2. Windows和Linux的ftp用法很不同.
    Windows自带的ftp支持interactive模式(如上所示), 或者-s从一个文件读取命令. 并且-v的作用和Linux下ftp刚好相反
   这些在help中均可见.
所以, 最好在Windows上用交互式登陆测试, 而在Linux下用脚本测试.

最后:  你看着#!/usr/perl/bin 不觉得别扭么