469,271 Members | 1,769 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

File::Remote - read a remote file

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;
  3. my $remote = new File::Remote;
  4. my $secure = new File::Remote(
  5.     rsh => "/bin/ssh",
  6.     rcp => "/bin/scp",
  7. );
  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: $!";
  14. print REMOTE "$_" while (<LOCAL>);
  16. $remote->close(LOCAL);
  17. $secure->close(REMOTE);
Aug 2 '07 #1
5 5909
3,503 Expert Mod 2GB
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);
As you can see, the example has the host in front of the file.


Aug 2 '07 #2
4,059 Expert 2GB
the problem appears to be here:


is rfile a file or a folder? Filenames without any extension are pretty uncommon.
Aug 2 '07 #3
3,503 Expert Mod 2GB
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.


Aug 3 '07 #4
4,059 Expert 2GB
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
3,503 Expert Mod 2GB
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.


Aug 3 '07 #6

Post your reply

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

Similar topics

2 posts views Thread by Boris Boutillier | last post: by
3 posts views Thread by Tony Murphy | last post: by
1 post views Thread by Venkat | last post: by
1 post views Thread by Magix | last post: by
3 posts views Thread by nicolasg | last post: by
6 posts views Thread by mmccaws | last post: by
5 posts views Thread by CSharp-Jay | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.