in reply to Re: Server access denied when checking for files
in thread Server access denied when checking for files

I know the paths to the folders are correct becuase if I take out the part where it actually moves the folders it works fine.

Here is the command line:
C:\Documents and Settings\Tim\My Documents\test1>perl readdir.plx
Access is denied.

Here is the code
#!/usr/bin/perl $dirtoget="\\\\Server\\Bankpro"; #directory to +read folders opendir(IMD, $dirtoget) || die("Cannot open directory"); #o +pen directory @thefiles= readdir(IMD); #store all files a +nd folders in directory into an array closedir(IMD); #close directory open (filenames, "dissmissed2.txt") || die ("Could not open file. <br> + $!"); #open list of file names $text = <filenames>; #read in one line +from txt file $defaultdir = "\\\\Server\\Bankpro"; # Directo +ry containing original folders $destinationdir = "\\\\Server\\BPdismis"; # Direct +ory to copy folders to foreach $f (@thefiles) #for each file i +n the directory { unless ( ($f eq ".") || ($f eq "..") ) #dont move + unless its a file of folder { while ($text){ #while there is a li +ne of text $text =~ s/\s+$//; #strip off whitesp +ace, newline and tabs system qq(move /y "$defaultdir/$text" "$destinationdir"); +#move files to diffrent directory $text = <filenames>; #read in next +line from file } } } close (filenames); #close list of files

Replies are listed 'Best First'.
Re^3: Server access denied when checking for files
by jhourcle (Prior) on Apr 26, 2005 at 01:20 UTC

    Then from the sounds of it, you don't have permission to write to the directories in which you're trying to move the files. There's also a slight chance that you don't have permission to modify the directory that you're attempting to move the files from (as you're effectively removing an item from that directory)

    Can you move files from the command line, without using perl? If so, is the Perl script running under any different permissions than your normal permissions?

      I am not at the office right now so I can not check if I can move folders from the command line without using perl or not, I will first thing in the morning, but how would I check or run the perl script's permissions?

      Thanks for the help.

        I'm not a windows person, so I don't know if they have a concept like suid (where the program is always run with another set of permissions). But they do have schedulers and the like. If the program is run through a scheduler, there's a reasonable chance that it's running with permissions other than your login. I'd suggest you talk to your system administrator. If you are the system administrator, I'd suggest that you take a look at the preferences and settings in whatever you're using to trigger the script.

Re^3: Server access denied when checking for files
by chas (Priest) on Apr 26, 2005 at 03:00 UTC
    I was trying to understand what you are attempting to do, but don't at all. Is this being run as a CGI; if not, why does the the error message for the first open have <br>? (It won't print to the browser because there is no content type line.) What does the comment "#dont move unless its a file of folder" mean? What do the files listed in dissmissed2.txt have to do with the entries in @thefiles? I don't understand what your last foreach loop is doing; it looks like for each $f in @thefiles (except . and ..), you are trying to do the same operations on the files listed in dismissed2.txt (but it looks like it will only be successful the first time.); isn't this latter file always the same independent of the value of $f?
    If I'm just being dense, please excuse...it's getting to be past my bedtime; but I've been looking at this for a while, and I can't make any sense of it.
    chas
Re^3: Server access denied when checking for files
by wazoox (Prior) on Apr 26, 2005 at 09:40 UTC
    You don't check every operation for success. You should check that readdir worked:
    @thefiles= readdir(IMD) or die "can't readdir: $!";
    And the most important part : check that you can actually "move" the files:
    system qq(move /y "$defaultdir/$text" "$destinationdir") or die "can't + move the file: $!";
    to understand where exactly the script fails.