Computer Hope
Software => Computer programming => Topic started by: acidblue on July 31, 2010, 10:37:33 AM
-
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"
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.
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();
-
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.