×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Net::FTP

Net::FTP

(OP)
Using the following code, I can download the required file to a wide open cgi-bin but how do I save the file to a directory outside the cgi-bin?

CODE

#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use Time::Local;
use warnings;
use strict;
use Net::FTP;
print "Content-type: text/html\n\n";	# prepare for HTML output

my $host = "ftp.website.co.uk";
my $user = "user";
my $password = "pass";

my $f = Net::FTP->new($host) or die "Can't open $host\n";
$f->login($user, $password) or die "Can't log $user in\n";

my $file = "my file name";
$f->get($file) or die "Can't get $file\n";
print "End"; 

Keith
www.studiosoft.co.uk

RE: Net::FTP

The easiest solution is to download it to a subdirectory of cgi-bin, and then remove access from that subdirectory using .htaccess.

Alternatively, you can use relative paths to access a directory outside of cgi-bin, but you'll of course have to set permissions right, which can be a challenge.

- Miller

RE: Net::FTP

(OP)
I was hoping to use the relative path method to a directory outside the cgi-bin but where do I add the path information?
The only path statement I have seen is with regard to the source file on the FTP server.

Keith
www.studiosoft.co.uk

RE: Net::FTP

(OP)
The solution was to change the local directory using standard Perl command chdir.

CODE

chdir "../www/ftp"; 

Keith
www.studiosoft.co.uk

RE: Net::FTP

Hi

Quote (audiopro)

The only path statement I have seen is with regard to the source file on the FTP server.
Huh ? What about get( REMOTE_FILE [, LOCAL_FILE [, WHERE]] )'s 2nd parameter ? Or what kind of Net::FTP module are you using ?

Feherke.
feherke.ga

RE: Net::FTP

(OP)
I tried many variations of

CODE

$f->get($file,'gotfile.txt',"../ftp") or die "Can't get $file\n"; 
but file was never downloaded so I assumed I was not using the right method.

Keith
www.studiosoft.co.uk

RE: Net::FTP

Hi

Sorry, but why have you specified the 3rd parameter ? According to the documentation that is file offset for continuing an interrupted download, not path.

I would try one of these :

CODE --> ( fragment )

$f->get($file,"../ftp/");

# or

$f->get($file,"../ftp/$file"); 

Feherke.
feherke.ga

RE: Net::FTP

(OP)
Sorry, it was one of the things I had tried.
I tried both of the options you suggested but neither of them worked.
Out of curiosity, I tried the syntax on another server and it works perfectly, so the problem is not correct syntax but something with the server setup.

From the example above, the script hangs on the line

CODE

my $f = Net::FTP->new($host) or die "Can't open $host\n"; 

there is no error message but it just hangs and being a shared server I do not have access to the error logs.
When I remove this line and all the code after it, the script completes and I tested the 'use Ftp::NET' command by changing the name of the loaded module to create an error.

Any thoughts what could be wrong here?
I have asked the ISP but they always come back with the line that they do not offer support with scripting.
This particular ISP don't offer useful support with anything despite charging top dollar.
I moved away from them for this very reason but this is a client's website hosted by them.

Keith
www.studiosoft.co.uk

RE: Net::FTP

Hi

Painful. My first bet would be firewall. If that is the problem, probably you can not do anything to solve it.

Feherke.
feherke.ga

RE: Net::FTP

(OP)
Thanks, I suppose it makes sense to limit what can be downloaded directly from other servers.

Keith
www.studiosoft.co.uk

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close