Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Opening a file to read during telnet in perl

by ramki067 (Acolyte)
on Oct 31, 2013 at 08:05 UTC ( #1060531=perlquestion: print w/ replies, xml ) Need Help??
ramki067 has asked for the wisdom of the Perl Monks concerning the following question:

I have a telnet session opened having username and password. I tried to open a file for reading but its giving me an error saying "No such file or directory" whereas i confirmed that file is there in the path by print command. Can we open a file to read during telnet session? or how can i open a file during telnet session? Please help. Here is my code and the file is ab.txt
use Net::Telnet; $t = new Net::Telnet (Timeout => undef, Dump_log=>"dump.log"); $username="sqa"; $password="4q2013"; $t->open("xx.xx.xxxx.com"); $t->login($username, $password); $cmd='cd '.'/projects/74/android-rfs/sys tem/app'; my $ldir="/projects/74/Android"; ipadd(); print $ip_add=@ipadd[2]; print "Value of \$t is:$t\n"; @lines=$t->cmd($cmd) or die "Cannot perform cmd:$!"; print @lines; $t->cmd("cp $nmn.apklist.txt $ldir\n"); $cmd1='cd '.'/projects/74/Android'; @lines1=$t->cmd($cmd1); print @lines1; $req_apks="/projects/74/Android/ab.txt"; print "Value of \$req_apks is: $req_apks\n"; ######### Installating APKs ################################ $path="$ldir/latest_apks"; @b= $t->cmd("cd $path\n"); print "cd:@b\n"; $t->cmd("./adb kill-server\n") or die "Cannot kill adb servers +:$!"; sleep(10); $t->cmd("./adb start-server\n") or die "Cannot start adb serve +rs:$!"; sleep(10); @line=$t->cmd("./adb devices\n"); print "adb:@line\n"; sleep(10); @cnt=$t->cmd("./adb connect $ip_add\n") or die "Cannot connect + adb to bo ard IP Address:$!"; print @cnt; sleep(5); open(F2, "$req_apks") or die "Cannot open APK Filelist file $req_apks: +$!"; while (my $req = <F2>) { print "Installing new package $req\n"; @b= $t->cmd("./adb install $req \n") or die "Cannot install:$! +"; print @b; print @b; sleep(3); } #$t->close; $t->cmd("./adb disconnect $ip_add\n"); sleep(6); $t->cmd("./adb kill-server\n") or die "Cannot kill adb servers after i +nstall:$!" ; sleep(10); close(F2); print "Listapk function ended\n"; sub ipadd { $ip='xx.xxx.xx.xx'; $ip_port='10005'; $port = new Net::Telnet->new( Host=>$ip,Port=>$ip_port); $port->write("ifconfig eth0\n"); while (my $line = $port->getline()) { if ($line=~/flags/) { @ipadd= split(" ",$line); #print $line; #print @ipadd[2]; goto ln; } else {} } ln: $port->close; }

Comment on Opening a file to read during telnet in perl
Download Code
Re: Opening a file to read during telnet in perl
by hdb (Prior) on Oct 31, 2013 at 08:34 UTC

    Where do you expect your file to be? Your statement

    open(F2, "$req_apks") or die "Cannot open APK Filelist file $req_apks: +$!";

    tries to open a file on the local, not the remote machine.

      OK. I'm already in telnet session.Then, how do i open a remote file from telnet session? Thanks.

        how do i open a remote file from telnet session?

        At first I thought, "you can't". But then I realised: Just the same as on your local host. That means, if you want perl to open your file, you will have to start a perl programme-or-script through your telnet session remotely.

        This is a correct answer to your question, but I guess it isn't what you wanted? If you mean to open a remote file and process it locally, then telnet is just the wrong protocol*

        Interactive terminal sessions and file transfer are different things. There tend to be protocols like ssh/scp/sftp or in the olden days telnet/ftp to address either issue.

        * telnet is the wrong protocol in most situations. Unless it is the early 1990es again. Or we're stuck in ciscoland.

        Cheers, Sören

        Créateur des bugs mobiles - let loose once, run everywhere.
        (hooked on the Perl Programming language)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1060531]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2015-07-01 21:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (22 votes), past polls