Reading File from Server - perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading File from Server - perl
# 1  
Old 03-02-2009
Reading File from Server - perl

Hey,

I'm trying to read a file from a server. Simple file with some numbers.
Here is the code i'm running.

Code:
use Net::SSH::Perl::SSH1 ;

$scon = Net::SSH::Perl->new ("com123.sever.mydomain.com",(protocol=>'2',port=>'22',debug=>'true'));
$scon->login("user123","pass123");
open(FILE, "/tmp/test.o") ||
print("Unable to open test.o");
{
  $line = <FILE>;
  while ($line ne "") {
    print ($line);
    $line = <FILE>;
  print "Reading file...";
  }
print "Exiting...";
}

Doesn't seem to be working, have i left something out?
# 2  
Old 03-03-2009
Guys,

I need some real help here. I'm stuck big time. This is what i have so far. I cannot figure out why its not running. It makes perfect sence to me, looks correct, but something is wrong.

Code:
sub calculate {
$scon = Net::SSH::Perl->new ("com123.user123.mydomain.com",(protocol=>'2',port=>'22'));
$scon->login("user123","pass123");
print "connected ...\n";

$data_file="test4.o";
open(DAT, "$data_file") || die("Could not open file!");
@raw_data=<DAT>;
foreach $num (@raw_data)
{
chomp($num);
($num1,$num2,$num3)=split(' ',$num);
print "Number 1 is $num1, Number2 is $num2, Number3 is $num3\n";
}
close(DAT);
}

I am recieving this error alot of the time..

Code:
Could not open file! at hello.pl line 43.

Could not open file! at hello.pl line 43.

    while executing
"::perl::CODE(0x55eb4cc)"
    invoked from within
".c.calc invoke "
    invoked from within
".c.calc instate {pressed !disabled} { .c.calc state !pressed; .c.calc invoke } "
    (command bound to event)

Line 43 is :
Code:
open(DAT, "$data_file") || die("Could not open file!");

if i change it to this to it
Code:
open(DAT, "+>" . $data_file) || die("Could not open file!");

Then it only creates file in my c: drive.

I'm calling this code from a tcl button which is set up as follows:

Code:
Tkx::ttk__button(".c.calc", -text => "Connect to server", -command => sub {calculate();});

I've used a mkdir command after the initall connection, but it creates the directory on my c: drive and not the server, this leads me to think its not connecting right.

Can someone please give me some direction to go with this!!!

Thanks,
Philip.

Last edited by Phi01; 03-03-2009 at 01:58 PM.. Reason: added content.
# 3  
Old 03-03-2009
Sorry I have no experience with what you are doing.
# 4  
Old 03-03-2009
What are you trying to do? Open a connection to a server and open a file there for reading? If so, you should know that Net::SSH::Perl is just the secure equivalent of Net::Telnet. Meaning, it opens a connection to the remote host, sends commands and receives answers. It cannot magically make available files that are non-local.

As for your error messages: you can improve the helpfulness of those by including
Code:
use strict;
use warnings;
use diagnostics;

and using $! in your error messages.
# 5  
Old 03-03-2009
No problem kevin, I just hope someone else can help me out, you seem to be the only person on this forum.
# 6  
Old 03-03-2009
Quote:
Originally Posted by pludi
What are you trying to do? Open a connection to a server and open a file there for reading? If so, you should know that Net::SSH::Perl is just the secure equivalent of Net::Telnet. Meaning, it opens a connection to the remote host, sends commands and receives answers. It cannot magically make available files that are non-local.

As for your error messages: you can improve the helpfulness of those by including
Code:
use strict;
use warnings;
use diagnostics;

and using $! in your error messages.
Yes, i want to connect to the server through ssh and read the file.

im using this
Code:
use Net::SSH::Perl::SSH1 ;

I'm not using telnet.
# 7  
Old 03-03-2009
Read my post again. Then read the documentation for Net::SSH::Perl (hopefully) again. Then meditate on the information. Then please show me where in the documentation for Net::SSH::Perl it says that you can use the module to open remote files, because I must have missed that bit when reading it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple Question about Reading file by Perl

Hi , I just write a simple function to read the file line by line. But when I run it it says out of memory. I am not sure about the root cause, Can someone help me out of this? :D #! /usr/bin/perl use strict; sub checkAPs{ my $NDPDir = "/home/eweiqqu/NCB/NDP_files/"; ... (1 Reply)
Discussion started by: Damon_Qu
1 Replies

2. UNIX for Dummies Questions & Answers

reading a file in Perl

If a form's action is the following Perl script how do I make it print the entire contents of the file on the screen? if(param()) { my $uploadedFile = param('file');#in the html page 'file' is the value of the name attribute of the input my $fh = upload($uploadedFile); ... (1 Reply)
Discussion started by: zerohour
1 Replies

3. Shell Programming and Scripting

Help with reading a specific portion of a file using PERL

Hello, I am trying to read from a file using PERL:confused, however i need to read specific portions of the file the file goes like this <Name 1 Hono <Name 2 Jack and so on anyways i need to be able to write a program that ONLY opens the lines beginning with "<"? so it would... (2 Replies)
Discussion started by: UNDstudent
2 Replies

4. Shell Programming and Scripting

Help need in perl script reading from file

Need perl script, data file will be csv format. I have text file contains 2 colums. Filename Foldernumber aaaa 13455 bbbb 23465 cccc 26689 I have two location 1. files present and 2. folders present. I need to search for file and folder if folder... (3 Replies)
Discussion started by: hnkumar
3 Replies

5. Shell Programming and Scripting

Help with perl script while reading a file

Hi Everyone, I am very new to perl, but came across a situation wherein I have to read a c++ header file and write the datatype, its identifier and also the length to an excel file. There can be other header files, in the directory but I should browse through the file which has only "_mef:" string... (9 Replies)
Discussion started by: ramakanth_burra
9 Replies

6. Shell Programming and Scripting

Perl: Reading data from other file

Hi, I am writting some perl scripts for daily backup process. In which I want to pass some data/referance from another txt file. Text file contains only one column and multiple rows. I want to pass this data to variables of another perl script. e.g. Refdoc.txt file contains data as: perl1... (3 Replies)
Discussion started by: n.dba
3 Replies

7. Shell Programming and Scripting

TCL Reading file from Server

I'm nearly finished developing my app, im programming it in tcl/tk. I just need to get 1 last thing done. When my app starts, i ask the user for username and password. These are stored on a file on a unix server. My problem is how do i read a file from a unix server, i've tried everything but... (3 Replies)
Discussion started by: Phi01
3 Replies

8. Shell Programming and Scripting

perl - reading from a file conditionally

Hi, I am new to perl. I want to read from a file on the basis of some conditions.. I want to define parameters in a configuration file in such a manner like... etc.. in my perl script, theer is a variable like this.. then i want to read values from first if block from the file... (1 Reply)
Discussion started by: shellwell
1 Replies

9. UNIX for Dummies Questions & Answers

perl - file reading - last line not displayed

Hi, Here is something that am trying with perl #! /opt/third-party/bin/perl open(fh, "s") || die "unable to open the file <small>"; @ch = (); $i = 0; while( $content = <fh> ) { if( $i <= 5 ) { push(@ch, $content); $i++; } else { $i = 1; foreach(@ch) { (8 Replies)
Discussion started by: matrixmadhan
8 Replies

10. Shell Programming and Scripting

Perl Reading from File

is there a perl equivalent to sscanf? or something where I get the strings separated by spaces? (1 Reply)
Discussion started by: karyn1617
1 Replies
Login or Register to Ask a Question