[問題] Expect 的疑問
小弟看到上面有板友回文說bbs自動回覆可以用expect 做
就很高興的跑去cpan找了expect下來看,用法看起來好像很簡單,
就很開心的寫了一支簡單的ftp 如下:
###############################################################################
use Expect;
#$Expect::Log_Stdout=1;
#$Expect::Debug=3;
#$Expect::Exp_Internal=1;
$hostname = "x.x.x.x";
($ftp = Expect->spawn("ftp $hostname")) || die "Couldn't spawn ftp,$!";
($ftp->expect(10,"Name ($hostname:root):")) || die "Never got username prompt "
.$ftp->exp_error()."\n";
print $ftp "\r";
($ftp->expect(10,"Password:")) || die "Never got password prompt, ".$ftp->exp_e
rror()."\n";
print $ftp "123456\r";
($ftp->expect(10,"ftp>")) || die "Never got ftp prompt, ".$ftp->exp_error()."\n
";
$ftp->debug(3);
$ftp->exp_internal(1);
(print $ftp "get file\r") || die $ftp->exp_error();
##############################################################################
奇怪的是我已經login成功了,但我的print $ftp "get file\r"
就好像石沉大海一樣完全沒有作用,我開debug mode 起來看,
感覺好像是 expect 到 "ftp>" 之後這個spawn 就關起來了...
想請各位幫小弟看一下 問題出在哪?
############################################################################
輸出如下:
Connected to x.x.x.x.
220 Welcome to TIGER FTP service.
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (x.x.x.x:root):
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
#Debug mod open
ftp> Closing spawn id(3).
at /usr/lib/perl5/site_perl/5.8.5/Expect.pm line 1415
Expect::hard_close('Expect=GLOB(0x876ea88)') called at /usr/lib/perl5/s
ite_perl/5.8.5/Expect.pm line 1605
Expect::DESTROY('Expect=GLOB(0x876ea88)') called at expect_ftp.pl line
0
eval {...} called at expect_ftp.pl line 0
spawn id(3) closed.
Pid 14465 of spawn id(3) terminated, Status: 0x01
#############################################################################
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.64.191.30
→
02/15 14:07, , 1F
02/15 14:07, 1F
Perl 近期熱門文章
PTT數位生活區 即時熱門文章