viper1503 has asked for the wisdom of the Perl Monks concerning the following question:

hello perlmonks, everybody!

I am currently working on a intranet website in our company and still learning on web and perl programming.

I have a website on a unix apache2 server with perl installed and there's an FTP option in my webpage to get archive files from an ftp server.

I use perl cgi NET::FTP module, with username,password provided at script and filename from the html form.

To check if my cgi perl ftp script runs at unix, i hardcoded the username/password/target file at ftp server and run it and works fine (can get the target file).

But when i try to run my cgi perl ftp script (with username/password/target file hardcoded) thru my website, i get error 500 Internal Server Error then i check the error logs and shows me below.

"...Cannot open Local file "target_file": Permission denied, referer: +http://www.???.com/get_FILE.html "...malformed header from script. Bad header=retrieving file from serv +er: get.cgi, referer: http://www.???.com/get_FILE.html
My cgi perl ftp script with username/password/target file hardcoded:
#!/usr/bin/perl -wT use Net::FTP; print "retrieving file from server\n"; $ftpobj = Net::FTP -> new ("100.eee.yyy.xxx"); $ftpobj -> login("user","pass"); $ftpobj -> cwd ("target_directory"); $ftpobj -> get ("target_file"); $ftpobj -> quit; print "file size ",-s "target_file"," bytes\n";

Can you help me out guys? I've put the permissions to 777 of the script and the directory but still same error "permission denied... :(

Thanks!

Replies are listed 'Best First'.
Re: cgi perl ftp question
by Corion (Patriarch) on Oct 02, 2009 at 06:35 UTC

    The current directory for target_file is not what you think it is. Put a chdir() to the directory you want into your script, or use absolute path names for your local files.

      Hi Corion...

      thanks! i got it...i should point to the script where the target_file will be placed by using chdir(). It worked! cool...