how can I upload an entire folder to the ftp server?
I’m trying to do the following:
$FTP->binary();
$FTP->mkdir($pfolder);
$FTP->put("$pPath$pfolder");
Of course I did before authentication .. just that when I run the code, the following message appears
Cannot open Local file C:\xampp\htdocs\MyProject: Permission denied
at projectUpload.pl line 41
— EDIT —
I found solution, here is the code:
sub upload {
my ( $bpath , $path , $FTP ) = @_;
$path .= '/' unless $path =~ /\/$/;
for my $i ( glob ( "$path*" ) ) {
$i =~ /(?:\/(.*))/;
if ( not -d $i ) {
if ( -f $i ) {
$FTP->put ( $i , $1 ) ;
}
} else {
$FTP->mkdir ( $1 ) ;
upload ( $bpath , $i , $FTP ) if -d $i ;
}
}
}
If you are using the standard
Net::FTPmodule, you must upload one file at a time. Thereare other modules, however, that allow you to upload/mirror entire directory trees.
You probably want to go the directory you created before uploading your files. A
$FTP->cwd($pfolder);should do the trick.The “Permission denied” issue is probably because
MyProjectis a directory (I guess). Locally, do achdir()to that directory, open it withopendir(), then iterate over the files withreaddir()and upload one file at a time.