473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

File::Remote - read a remote file

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
5 6233
numberwhun
3,509 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);
  5.  
As you can see, the example has the host in front of the file.

Regards,

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

Regards,

Jeff
Aug 3 '07 #4
KevinADC
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
numberwhun
3,509 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.

Regards,

Jeff
Aug 3 '07 #6

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

Similar topics

2
by: Boris Boutillier | last post by:
HI all, I came across a strange behaviour with read method, and I'm not sure if this is a filesystem problem or a misuse of this method. I do the simple following thing : f = open...
3
by: Tony Murphy | last post by:
Strange problem, I read a file into a string using ifstream, ostringstream and string and end part of the file is missing (file size ~9.5kb, ~9k read). its a html file. using windows nt 4 ...
1
by: Venkat | last post by:
Hi, I am buried with the following issue on Linux platform, please let me know if someone can help me out. I am using ifstream to open and read the file, even i am able to open the file i am...
1
by: Magix | last post by:
Hi, I have these string data: str_data1, str_data2, str_data3, which capture some value after a routine process A. Then I would like to write (append) these 3 string values into a text file each...
4
by: xenny | last post by:
Hi, I'm trying to see if a file (exportfile) is set to read only using File::GetAttributes: if ((File::GetAttributes(exportfile.c_str()) & FileAttributes::ReadOnly) != 0); {...
3
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its...
2
by: js | last post by:
Hi list. I'm writing a tail -f like program in python and I found file.read() doesn't work as I think it should. Here's the code illustrating my problem. ### #!/usr/bin/env python import...
6
by: mmccaws | last post by:
I understand that one can use FILE::REMOTE for SSH and SCP sessions. However I don't see how to apply the login password or the userID in the examples. Am I misreading the intent of the module? ...
5
by: CSharp-Jay | last post by:
So I have been programming in C# on a personal level as of lately, and am curious about something. Lately I have been experimenting around with file create/write, etc. I can open and read the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.