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; }

In reply to Opening a file to read during telnet in perl by ramki067

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.