Perl FTP Get Help

M

mparker

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!

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

Code:

#!/usr/bin/perl

use Net::FTP;

my $ftp = Net::FTP->new("ftp.domain.com", 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/ );
}

$ftp->cwd("/photoext");

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

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

$ftp->cwd("/OpenHouse");

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

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

$ftp->quit;
 
M

Mart van de Wege

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!

Errors:
Cannot open Local file agents.txt: Permission denied

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.

Mart
 
T

Tad J McClellan

Mart van de Wege said:
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.


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. :)
 
N

Nathan Keel

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!

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


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

How to login using PDO 3
ls in ftp fails 5
Net::FTP and IBM TSO :-( 15
ftp perl script problem.. 8
Python install regression test fail 0
Net::FTP: cwd(' ') 5
Help: Login FTP 5
Python battle game help 2

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top