October 31st, 2013, 03:31 AM
Opening a file to read during telnet in perl
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
$t = new Net::Telnet (Timeout => undef, Dump_log=>"dump.log");
print "Value of \$t is:$t\n";
@lines=$t->cmd($cmd) or die "Cannot perform cmd:$!";
$t->cmd("cp $nmn.apklist.txt $ldir\n");
print "Value of \$req_apks is: $req_apks\n";
######### Installating APKs ################################
@b= $t->cmd("cd $path\n");
$t->cmd("./adb kill-server\n") or die "Cannot kill adb servers:$!";
$t->cmd("./adb start-server\n") or die "Cannot start adb servers:$!";
@cnt=$t->cmd("./adb connect $ip_add\n") or die "Cannot connect adb to bo
ard IP Address:$!";
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:$!";
$t->cmd("./adb disconnect $ip_add\n");
$t->cmd("./adb kill-server\n") or die "Cannot kill adb servers after install:$!"
print "Listapk function ended\n";
$port = new Net::Telnet->new( Host=>$ip,Port=>$ip_port);
while (my $line = $port->getline())
@ipadd= split(" ",$line);
October 31st, 2013, 08:33 AM
You have received some answers on your cross post on Perl Monks.
The telnet protocol enables you to run commands on the distant machine, so you could run a Perl program on the distant machine, but it is not intended to open a remote file from your local platform.
Consider the FTP/SFTP protocols to download the file and read it locally.
You could possibly try to run a telnet remote command (something like my $content_in_1_string = `cat remotefile.txt`; or my @content_in_lines = `cat remotefile.txt`; ) to list the file and get the content locally (I don't know if this really works and can't try it now), but this is essentially equivalent to downloading the file, and FTP/SFTP protocols would be much better suited.
October 31st, 2013, 09:20 AM
Take a look at File::Remote - Read/write/edit remote files transparently