Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Perl help "permission denied" when reading files from directory.  (Read 10225 times)

0 Members and 1 Guest are viewing this topic.

acidblue

    Topic Starter


    Rookie

    I'm getting a "permission denied" error from the local computer,(WinXp), when I try reading files to upload  to my FTP server.
    This happens whether its a single file or reading multiple files from a directory.
    Also tried with passive on or off.

    Reading from directory error:
    "Cannot open Local file C:\Documents and Settings\user\Folder1\Folder2\file: Permission denied"



    Code: [Select]
    use File::HomeDir;
    use Net::FTP;


    $path=home()."\\My Documents\\My Pictures";

    my $server    = "FTP.server.net";
    my $username  = "usr";
    my $pass      = "pass";

    print "Connecting to $server..";

    # Set up connection
    $ftp = Net::FTP->new( $server, Passive => 0, Debug => 3 ) or die $@;
    print "..authenticating..";

    # Log in...
    $ftp->login( $username, $pass ) or die $ftp->message;
    print "..done!\n";

    print $ftp->pwd (), "\n";
    $ftp->cwd('/ftp') or die $ftp->message;
    print $ftp->pwd (), "\n";

    # set mode to binary
    $ftp->binary();

    # read local directory to upload files
    opendir(DIR, "$path");
    my @files = readdir(DIR);
    foreach my $file (@files)
        {
        if (not -d $file)
            {
           
           
            $ftp->put("$path\\$file") or die " Upload error, quiting..";
            }
        }
    $ftp->quit();


    Single file code give a "permission denied" error.

    Code: [Select]
    use Net::FTP;
    use File::HomeDir;

    my $server = "ftp.server.net";
    my $username  = "user";
    my $pass      = "pass";


    $path=home()."\\My Documents\\My Pictures";

    print "Connecting to $server..";

    # Set up connection
    $ftp = Net::FTP->new( $server, Passive => 1, Debug => 1 ) or die $@;
    print "..authenticating..";

    # Log in...
    $ftp->login( $username, $pass ) or die $ftp->message;
    print "..done!\n";

    print $ftp->pwd (), "\n";
    $ftp->cwd('/') or die $ftp->message;
    print $ftp->pwd (), "\n";

    # Upload file

    $ftp->binary();
    $ftp->put("$path\\File.txt");
    $ftp->quit();

    acidblue

      Topic Starter


      Rookie

      Re: Perl help "permission denied" when reading files from directory.
      « Reply #1 on: August 01, 2010, 05:54:37 PM »
      Ok I figured it out, it was the "or die" part of my code.
       
      When ever it came to a folder the script would quit giving me the "Permissions error".

      Removing the 'or die" part seems to solve this. Actually changing it to 'warn' is probably better.

      Now if I can figure out how to upload folders recursively that would be great.