麻烦帮我看一下telnet到远程主机,然后用ftp接连到一台服务器传文件的问题!
jjqing
|
1#
jjqing 发表于 2008-10-11 23:47
麻烦帮我看一下telnet到远程主机,然后用ftp接连到一台服务器传文件的问题!
在上一个问题中,在本地用system语句进行ftp连接传文件的问题已经解决,现在我把这个语句用到telnet模块中的cmd方法中,从远程主机往一台FTP服务器进行FTP连接,却出现了问题,在telnet中执行的ftp命令,没有产生ftp连接:
1、system语句如下: system "ftp -n \<\<EOF \n open $my_ftp_host \n user $my_ftp_user $my_ftp_password \n bin \n prompt \n lcd $my_ftp_dir \n cd $my_ftp_upload_dir \n put $my_ftp_file \n bye \n\<\<EOF"; 2、cmd语句如下: $telnet -> cmd("/bin/ksh -c \"export LANG=$my_lang;ftp -n \<\<EOF \nopen $my_ftp_host \nuser $my_ftp_user $my_ftp_password \nbin \nprompt \nlcd $my_ftp_dir \ncd $my_ftp_upload_dir \nput $my_ftp_file \nbye \nEOF\" "); #这条语句运行没有报错,正常执行完,然后程序退出,但是没有产生我希望的FTP连接。 3、产生的telnet_input日志如下: root@solaris01 # more telnet_input.log login: root Password: Last login: Sat Oct 11 23:24:17 from solaris01 Sun Microsystems Inc. SunOS 5.10 Generic January 2005 You have new mail. Sourcing //.profile-EIS..... root@solaris01 # /bin/ksh -c "export LANG=C;cd /opt/SUNWexplo/output/;ls *.gz" explorer.33bd5136.solaris01-2008.10.10.14.07.tar.gz root@solaris01 # /bin/ksh -c "export LANG=C;ftp -n <<EOF open 3.3.3.1 user 123 123 bin prompt lcd /opt/SUNWexplo/output/ cd upload put explorer.33bd5136.solaris01-2008.10.10.14.07.tar.gz bye EOF" root@solaris01 > 4、ftp服务器的日志如下: 在使用local模块时,日志中显示有FTP连接: [5] Sat 11Oct08 23:30:33 - (000003) Connected to 3.3.3.10 (Local address 3.3.3.1) [5] Sat 11Oct08 23:30:33 - (000003) User 123 logged in [4] Sat 11Oct08 23:30:33 - (000003) Receiving file c:\ftp_upload\explorer.33bd5136.solaris01-2008.10.10.14.07.tar.gz [4] Sat 11Oct08 23:30:33 - (000003) Received file c:\ftp_upload\explorer.33bd5136.solaris01-2008.10.10.14.07.tar.gz successfully (7070 kB/sec - 3670303 Bytes) [5] Sat 11Oct08 23:30:33 - (000003) Closing connection for user 123 (00:00:00 connected) 但是在使用telnet模块时,日志中没有任何信息,表示没有ftp连接。 我的程序是这样的,定义一个ftp子程序,这个子程序支持本地运行与telnet到远程主机运行两种模式,如果是本地运行,则使用system语句,如果是telnet到远程主机,然后进行ftp连接,则使用telnet的cmd方法。 我的子程序如下,稍微有点长: sub explorer_ftp { print "This is for explorer ftp \n"; if (!$my_ftp_host) { $my_ftp_host = "127.0.0.1"; } else { $my_ftp_host = $my_ftp_host; } if (!$my_ftp_user) { $my_ftp_user = "root"; } else { $my_ftp_user = $my_ftp_user; } if (!$my_ftp_password) { $my_ftp_password = "root"; } else { $my_ftp_password = $my_ftp_password } if (!$my_ftp_upload_dir) { $my_ftp_upload_dir = "upload"; } my $my_full_upload_path; if ($my_ftp_host eq "127.0.0.1") { #root:x:0:0:Super-User:/:/sbin/sh my @my_root_home = `cat /etc/passwd`; chomp (my ($my_root_home) = grep /^root/,@my_root_home); $my_root_home = (split /:/,$my_root_home)[5]; #print "\$my_root_home is \n $my_root_home \n"; $my_full_upload_path = "$my_root_home" . "$my_ftp_upload_dir"; if (! -e "$my_full_upload_path") { mkdir $my_full_upload_path; #print "$my_full_upload_path \n"; } } print "\$my_ftp_host is $my_ftp_host \n"; print "\$my_ftp_user is $my_ftp_user \n"; print "\$my_ftp_password is $my_ftp_password \n"; print "\$my_ftp_upload_dir is $my_full_upload_path \n"; if ($my_local == 1) { print "ftp in local \n"; #取得文件路径 #$my_ftp_file @my_result = `cd /opt/SUNWexplo/output/;ls *.gz`; print "\@my_result is \n @my_result \n"; #& clear_prompt; #print "\@my_result is \n @my_result \n"; chomp ($my_ftp_file = shift (@my_result)); print "\$my_ftp_file is \n $my_ftp_file \n"; #开始FTP system "ftp -n \<\<EOF \n open $my_ftp_host \n user $my_ftp_user $my_ftp_password \n bin \n prompt \n lcd $my_ftp_dir \n cd $my_ftp_upload_dir \n put $my_ftp_file \n bye \n\<\<EOF;"; #上面这段是成功的 } elsif ($my_telnet == 1) { & my_telnet_login; print "ftp in remote \n"; @my_result = $telnet -> cmd("/bin/ksh -c \"export LANG=$my_lang;cd /opt/SUNWexplo/output/;ls \*.gz\" "); & clear_prompt; print "\@my_result is \n @my_result \n"; chomp ($my_ftp_file = shift (@my_result)); print "\$my_ftp_file is \n $my_ftp_file \n"; $telnet -> cmd("/bin/ksh -c \"export LANG=$my_lang;ftp -n \<\<EOF \n open $my_ftp_host \n user $my_ftp_user $my_ftp_password \n bin \n prompt \n lcd $my_ftp_dir \n cd $my_ftp_upload_dir \n put $my_ftp_file \n bye \n EOF\" ") #这段执行有问题,似乎根本没有进行FTP连接(从FTP日志中可以看到) } } }#my_explorer子程序结束 |