By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,823 Members | 730 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,823 IT Pros & Developers. It's quick & easy.

File::Remote - read a remote file

P: 76
hi guys,
I'm trying to figure how to read a file from my other computer, and here is what i did. it doesn't work for some reason. i would really appreciate if you could help me with this.
i get this error message:
Open failed at local: No such file or directory

thank you.

Expand|Select|Wrap|Line Numbers
  1. use File::Remote;
  2.  
  3. my $remote = new File::Remote;
  4. my $secure = new File::Remote(
  5.     rsh => "/bin/ssh",
  6.     rcp => "/bin/scp",
  7. );
  8.  
  9. $remote->open(LOCAL, "/Users/lab/Desktop/NewInstall/rfile")
  10.     or die "Open failed at local: $!";
  11. $secure->open(REMOTE, "123.456.789.10:/Users/lab/databases/file.txt")
  12.     or die "Open failed at remote: $!";
  13.  
  14. print REMOTE "$_" while (<LOCAL>);
  15.  
  16. $remote->close(LOCAL);
  17. $secure->close(REMOTE);
  18.  
Aug 2 '07 #1
Share this Question
Share on Google+
5 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
First, PLEASE, always put your code inside of code tags. It helps keep our moderator(s) work down.

Second, I think you have your code confused. You are doing a $remote and trying to open a file, but you are not specifying the host. If you look at this page, you will see the following in the example:

Expand|Select|Wrap|Line Numbers
  1.    # read from a remote file
  2.    open(REMOTE, "host:/remote/file") or die $!;
  3.    print while (<REMOTE>);
  4.    close(REMOTE);
  5.  
As you can see, the example has the host in front of the file.

Regards,

Jeff
Aug 2 '07 #2

KevinADC
Expert 2.5K+
P: 4,059
the problem appears to be here:

/Users/lab/Desktop/NewInstall/rfile

is rfile a file or a folder? Filenames without any extension are pretty uncommon.
Aug 2 '07 #3

numberwhun
Expert Mod 2.5K+
P: 3,503
I agree, but I wonder if it is also a matter of syntax. In his example, he is using:

$remote->open(LOCAL, "/Users/lab/Desktop/NewInstall/rfile")

but the perldoc page for the module shows to just use the standard open function as such:

# read from a remote file
open(REMOTE, "host:/remote/file") or die $!;

I think this might be where the issue is, unless of course his syntax is possible and I don't know it, which is always likely as I haven't used this module.

Regards,

Jeff
Aug 3 '07 #4

KevinADC
Expert 2.5K+
P: 4,059
I think you can name the filehandles anything you want. I'm pretty sure the module documentation uses LOCAL and REMOTE in the examples for clarity. The important bit is using the "host:" syntax if it is a remote file. Where "host" is the domain name or IP address I assume.
Aug 3 '07 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
Actually, I wasn't even looking at the filehandle. I was focusing on the fact that he hadn't specified the host, so we are thinking along the same lines. The machine, without the host, thinks it is opening the file on the local machine at the specified path.

Regards,

Jeff
Aug 3 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.