mukkollu has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to write code on Windows server A to read files from Windows server B. Here is the code piece.

$logdir = "\\\\Server\\e\$\\log"; opendir($fd, $logdir) or die "Cannot open directory: $!"; @AllFiles = readdir($fd); print "$_\n" for @AllFiles;

This code neither throws error nor prints files. Files do exist in the log folder. I was able to view the files from windows explorer and command prompt from server A.

Replies are listed 'Best First'.
Re: Cannot read files from folder on another windows server
by BrowserUk (Patriarch) on Sep 16, 2011 at 10:18 UTC

    The only reasons I can think of why that might not work are:

    • visibility;

      When you try it from the Explorer, you've previously done a Tools->Map network drive, but you haven't done the equivalent before running the script.

    • permissions;

      When you run the script, it is running under a different account -- say a webserver id -- that doesn't have permission to access the network.

    What output do you see if you add the following to the top of your script:

    warn `net share`; warn `dir \\\\Server\\e\$`; ...

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I did not map the network drive previously. I can list files using the below command
      dir \\Server\e$\log
      I was using the same account on both the servers.
        I have figured out a way to do this...
        @files = `dir $logdir \| grep -i abc_`;

        Unless you've got a bug in your perl, your script works. I've run your script and all I changed was the machine-name.

        Strawberry perl 5.12.3 on an XP virtual-machine, connecting back to itself.

Re: Cannot read files from folder on another windows server
by Anonymous Monk on Sep 16, 2011 at 09:05 UTC

    If in doubt, print your variables.

    You're using double-quotes when making $logdir and I'm guessing $\ is being treated as a variable (it's line-ending or record-separator or some such iirc).

      I have printed variables and the $logdir string. I was able to access the logdir that was printed from command prompt to list files.
Re: Cannot read files from folder on another windows server
by Anonymous Monk on Sep 16, 2011 at 01:56 UTC

    Hi,

    Are you short a \ before the $?

    J.C.

      No, «\\Server\e$\log» is indeed the string he wants to create. («e$» refers to «e:»)