Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
laziness, impatience, and hubris
 
PerlMonks  

Cannot acces a remote file

by chennaiite (Sexton)
on Aug 22, 2005 at 05:48 UTC ( #485616=perlquestion: print w/ replies, xml ) Need Help??
chennaiite has asked for the wisdom of the Perl Monks concerning the following question:

open(REMOTE,"\\172.22.1.73\D:\FromC\FitClass\fooo.LOG") || die ("cannot open the remote file $!");
This line does not works for me when i access a file from a remote machine in windows....why?

I have username and passward for that remote machine....

how to access this remote file....

Can anybody help me in this regard....Please...

Thanks.....

Comment on Cannot acces a remote file
Re: Cannot acces a remote file
by Roger (Parson) on Aug 22, 2005 at 05:56 UTC
    Your URL for the remote file is wrong in several places.

    1. Backslashs inside the string. The backslash will escape the next character. You will need two backslashes to represent a single backslash.
    eg. "\\\\172.x.x.x\\foo\\bar"

    2. How the "D:" drive is exported from the other machine. I would think that something like
    "\\\\172.x.x.x\\D\\foo\\bar\\filename"
    would be more appropriate.

    But I am not an expert in Windows, so you could be right in 2, but 1 is definitely wrong.

      Thanks Roger.... I tried both...but no result...

      It throws cannot open the remote file invalid argument....

      Is there anyother way to access the remote file.....

      Just I want to copy the remote file to local and then make changes,Finally save new updated file in remote place...

        How is the remote drive exported in the first place? Can you browse it at all? Why don't you open the explorer session, and manually browse to the location of the file under the NETWORK NEIGHBOURHOOD, and grab the fullpath name in the address bar. Then apply the double backslash bits to make it work?

        chennaiite,

        open cannot authenticate to the server for you.

        1. Make the changes roger has mentioned (i guess you have done that already)

        2. Now go to start->RUN and then type \\IP_ADDRESS (corresponding to your server)

        3. It will ask you to authenticate, type login and password

        4. Now try you perl script again

        I tried to access the files from one of my computers on my network and i get Invalid argument at -e line 1.

        Ignore the -e part as i was using command line perl. After I authenticated with the machine like the way i just explained i was able to access the file

        Hope this helps. I am not sure how windows's fileserver works with authentication and hence don't know ways to automate it.

        On the other hand you can also map your network server to a drive and try to see if that works better for you?

        update: if you don't know what path to use, just start->run type the ip_address\ and then browse to the directories. In windows explorer if you have turned on "address" bar then you can copy that into your open call. Just make sure you escpate \ with \\

        cheers

        SK

        Does the remote machine have an FTP server (and this file available through it)? If so, this task would be very easy with Net::FTP. But if not, as Roger says you need to determine how the file is shared by windows.

        It seems you first have to mount a share on the other server... try Win32::NetResource from CPAN, that does a good job

        If you want to find out what to do, try the dosbox command

        net use z: \\172.22.1.73\D$ /user:administrator secret

        (if secret is the password). If you type \\172.22.1.73 in your windows explorer and you see the share (e.g. with the name d), then use something like

        net use z: \\172.22.1.73\D /user:me secret

        (net help use gives you more information about this)

        If that works fine, you've got enough information to mount it with Win32::NetResource

        Best regards,
        perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

      Actually, using "D$" should work, even without creating a share. Windows provides a "secret" share for every drive where the name of the share is the drive letter followed by a dollar sign. These shares are possibly only available to admins.
      $path = '\\\\172.x.x.x\\D$\\foo\\bar\\filename';

      Update: Fixed the problem davidrw pointed out.

        the dollar sign needs escaping, too:
        $path = "\\\\172.x.x.x\\D\$\\foo\\bar\\filename";
Re: Cannot acces a remote file
by davidrw (Prior) on Aug 22, 2005 at 06:13 UTC
    first, see Roger's comments. second, to help debug, change your code so it's in the form:
    my $file = "\\172.22.1.73\D:\FromC\FitClass\fooo.LOG"; warn $file; open(REMOTE,'<', $file) or die ("cannot open the remote file '$file': +$!");
    Now, take the string from the warn line (let's assume it printed "foo at script.pl line 1234") and try to run start foo from a dos prompt. Does this work? If not, is it because the UNC path is malformed? Note that it could work but your script still doesn't due to permissions issues -- for example if this is being used from a CGI script make sure that the web server (the IIS user account) has permission to read that file.
      Thanks a lot for u all....

      Now I am able to access remote file.....

      The only thing is that,i have to make the server machine to map a particular folder as sharable then only my code works perfectly.....

      Also only after authenticaion my code works.....

      Now i am in the stage of analysing the Win32::NetResources module..... Can anybody suggest me how far this module is helpfull for me...
      If you have anycode using this module please provide it might save my time...
      Thanks in advance......
        The only thing is that,i have to make the server machine to map a particular folder as sharable then only my code works perfectly.

        Wow, you can only access a file that the owner wants you to access? How refreshing for Windows! Honestly, did you think you could just ask any machine for any file anywhere?

        --
        [ e d @ h a l l e y . c c ]

Re: Cannot acces a remote file
by puploki (Hermit) on Aug 22, 2005 at 09:23 UTC
    As an aside, decent versions of Windows (2000, XP, Vista) will quite happily open UNC paths with forward slashes rather than back slashes which avoids all that nasty escaping in Perl. So:
    //myserver/c$/windows/foo.txt
    and
    c:/windows/foo.txt
    all work a treat.
Re: Cannot acces a remote file
by Anonymous Monk on Aug 23, 2005 at 21:07 UTC
    Have you tried? open(REMOTE,"//172.22.1.73/D/FromC/FitClass/fooo.LOG") || die ("cannot open the remote file $!"); or open(REMOTE,"\\\\172.22.1.73\\D\\FromC\\FitClass\\fooo.LOG")
      Hi Monk... I tried $path = "\\\\172.x.x.x\\D\$\\foo\\bar\\filename";
      Also i tried your script...But it says Permission denied...
      How to rectify the error,but i have the permision to access the remote file....
      Can anybody give me suggestions....
      Thanks in advance

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://485616]
Approved by Roger
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2014-04-25 02:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (579 votes), past polls