Chinaunix

标题: perl+expect+ftp,为什么登陆失败 [打印本页]

作者: andy820303    时间: 2010-04-19 14:20
标题: perl+expect+ftp,为什么登陆失败
对于telnet服务,expect模块可以正常工作,但是对于ftp服务,总是“login failed”

use Expect;
use strict;

my $timeout = 2;
my $cmd = "ftp";
my $exp = Expect->spawn($cmd,"192.168.32.11") or die "Can't spawn $cmd!";
$exp->expect($timeout,-re=>'^Name \(*\):');
$exp->send("administrator\r\n");
$exp->expect($timeout,-re=>'Password:');
$exp->send("arkivio\r\n");
$exp->expect($timeout,-re=>'ftp>');
$exp->send("get policyxml-nfs.xml\r\n");

简单看了一下输出,发现问题是:用户名和密码都被重复输入了3次。这是为什么呢?

ftp> ftp> -bash-3.00# perl test-ftp.pl
Connected to 192.168.32.11.
220 Microsoft FTP Service
Name (192.168.32.11:root): administrator

administrator
administrator



331 Password required for administrator.
Password:
arkivio

arkivio
arkivio



530 User administrator cannot log in.
Login failed.
ftp> ?Invalid command
ftp> ftp> -bash-3.00#
作者: andy820303    时间: 2010-04-19 14:58
为什么从效果来看,用户名和密码都被输入了3次呢?
作者: andy820303    时间: 2010-04-19 15:58
问题解决了,最后放弃使用expect+ftp了,改用Net::FTP,很方便
作者: yybmsrs    时间: 2010-04-19 16:20
问题解决了,最后放弃使用expect+ftp了,改用Net::FTP,很方便
andy820303 发表于 2010-04-19 15:58



    当初为什么要用expect呢?
作者: andy820303    时间: 2010-04-20 15:33
回复 4# yybmsrs

接触perl时间不长,不知道Net::FTP.

而且看起来expect和telnet结合的还不错,就想当然了
作者: bentlycn    时间: 2010-04-22 21:03
当初为什么要用expect呢?
yybmsrs 发表于 2010-04-19 16:20



    +1




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2