Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Net::FTP 1

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
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
 
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
 
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
 
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
 
Hi

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

I would try one of these :
Code:
$f->get($file,[green][i]"../ftp/"[/i][/green]);

[gray]# or[/gray]

$f->get($file,[green][i]"../ftp/$file"[/i][/green]);


Feherke.
feherke.ga
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top