Perl FTP Get Help

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I posted all of my code below for easy reference. I have this code
setup to connect to an FTP server and download some files. It works
great when I login as root. However, when I run this in cron I get the
error below. I set the directory permissions to 0777 just to see if it
would work and I get the same error.

Does anyone have any thoughts or any recommendations on what I can
look at to begin troubleshooting?

Thanks in advance!

Cannot open Local file agents.txt: Permission denied
at /var/www/vhosts/ line 12
Cannot open Local file commercial.txt: Permission denied
at /var/www/vhosts/ line 13
Cannot open Local file condominium.txt: Permission denied
at /var/www/vhosts/ line 14
Cannot open Local file multifamily.txt: Permission denied
at /var/www/vhosts/ line 15
Cannot open Local file offices.txt: Permission denied
at /var/www/vhosts/ line 16
Cannot open Local file residential.txt: Permission denied
at /var/www/vhosts/ line 17
Cannot open Local file vacantland.txt: Permission denied
at /var/www/vhosts/ line 18
Cannot open Local file photos.txt: Permission denied
at /var/www/vhosts/ line 26
Cannot open Local file openhouse.txt: Permission denied
at /var/www/vhosts/ line 34



use Net::FTP;

my $ftp = Net::FTP->new("", Debug => 0);

$ftp->login("username", "password");

my @file_list = $ftp->ls();

foreach (@file_list) {
        $ftp->get($_, 'agents.txt') if ( $_ =~ m/idxag.*?\.txt/ );
        $ftp->get($_, 'commercial.txt') if ( $_ =~ m/idxcm.*?
\.txt/ );
        $ftp->get($_, 'condominium.txt') if ( $_ =~ m/idxcn.*?
\.txt/ );
        $ftp->get($_, 'multifamily.txt') if ( $_ =~ m/idxmf.*?
\.txt/ );
        $ftp->get($_, 'offices.txt') if ( $_ =~ m/idxof.*?\.txt/ );
        $ftp->get($_, 'residential.txt') if ( $_ =~ m/idxrs.*?
\.txt/ );
        $ftp->get($_, 'vacantland.txt') if ( $_ =~ m/idxvl.*?
\.txt/ );


my @file_list = $ftp->ls();

foreach (@file_list) {
        $ftp->get($_, 'photos.txt') if ( $_ =~ m/photos.*?\.txt/ );


my @file_list = $ftp->ls();

foreach (@file_list) {
        $ftp->get($_, 'openhouse.txt') if ( $_ =~ m/openhouse.*?
\.txt/ );


Re: Perl FTP Get Help

Quoted text here. Click to load it

From the error it is obvious that your script cannot write out the
local file. If you have set the directory permissions to 777, then it is
also obvious that the script is not trying to write in that directory,
or it wouldn't get a permission denied error.

So, what you need to do is find out what the working directory is for
your script.


"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.

Re: Perl FTP Get Help

Quoted text here. Click to load it
Quoted text here. Click to load it

If the program simply chdir()s to the directory it wants to be in,
then what the old, default, working directory was will not matter.  :-)

Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Re: Perl FTP Get Help wrote:

Quoted text here. Click to load it

Check the permissions/ownerships of the directory itself, but also the
parent directory, as well as the file if it already exists.

Site Timeline