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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File downloading 1

Status
Not open for further replies.

imad77

Instructor
Oct 18, 2008
97
CA
Hi,

I am newbie in Perl/CGI and I need your help to develop a little script to help me to download some files located in a FTP server via HTTP to a disk.

I need to authenticate with username/password via a HTTP page and I can choose the files to download from the web page to my disk.

Can someone help me to get this script?

Thanks a lot in advance.
 
Hi,

I tried to develop with Perl this code but I experienced some issues and I cannot retrieve a file from an FTP server (Unix) to a local disk (c:\) in a desktop(Windows).

Here is the code:

#!/usr/bin/perl
use strict;
use warnings;
use Net::FTP;

my $backup_dir = "C:/partage";
my $remote_backup_dir = "/home/toto";
my $remote_file = "toto.txt";
my $dir = "/home/toto";

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

$ftp->login('toto','pass10');
$ftp->cwd($dir) || die "Unable to change directories";
$ftp->binary();
$ftp->get($remote_file,"toto.txt");
$ftp->quit;


I get this error when I try to run this code from a website as:

and I get this error message:
Internal Server Error

Thanks in advance.
 
The FTP server is at 192.168.1.17?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Get it working from the command line first before you try and get it working from the web page.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Yes, 192.168.1.17 is a FTP and HTTP server.
I tried from the command and it works fine.
I can get and put file from a Windows PC to this FTP server Unix.
 
See if this helps:

Code:
#!/usr/bin/perl
use strict;
use warnings;
use Net::FTP;
use CGI::Carp qw/fatalsToBrowser/;
print "Content-type: text/html\n\n";

my $backup_dir = "C:/partage";
my $remote_backup_dir = "/home/toto";
my $remote_file = "toto.txt";
my $dir = "/home/toto";

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

$ftp->login('toto','pass10');
$ftp->cwd($dir) || die "Unable to change directories";
$ftp->binary();
$ftp->get($remote_file,"toto.txt");
$ftp->quit;

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hi Kevin,

I tried your suggestion but I experience another Software error. All of lines are working fine but the script stops at this software error located in this line of
$ftp->get($remote_file,"$backup_dir/$pp")
I use FTP server on RedHat and the workstation Windows XP.

Any idea about this command?


#!/usr/bin/perl -w
use strict;
use warnings;
use Net::FTP;
use CGI::Carp qw(fatalsToBrowser);

print "Content-type: text/html\n\n";

my $backup_dir = "C:/toto";
my $remote_backup_dir = "/home/toto";
my $remote_file = 'toto.txt';
my $dir = "/home/toto";
my $pp="toto.txt";
my $user="toto";
my $pass="pass10";
my $ftp = Net::FTP->new("192.168.1.17", Debug => 1, Passive => 1) or die "hihi";
$ftp->login($user,$pass) || die "Unable to login";
$ftp->cwd($dir) || die "Unable to change directories";

$ftp->binary();

$ftp->get($remote_file,"$backup_dir/$pp") or die "Unable to get file";
$ftp->quit or die "Could not close the connection cleanly: ";
 
try like this:

$ftp->get($remote_file,$backup_dir) or die "Unable to get file : $!";



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hi Kevin,

I tried it but I get the same error. Any other suggestion?

Thanks a lot for your great help.
 
Hi Kevin,

I tried it but I get the same error.

I tried another thing where I changed the content of :
my $backup_dir = "C:/toto";

by this content:
my $backup_dir = "/home/work/toto.txt";

When I run this script via HTTP, it works fine and the file is copied in /home/work.
I think that something is wrong with the path located in Windows workstation.


Any other suggestion?

Thanks a lot for your great help.
 
In the modules documentation it shows a method called "message" , I suggest you try it:

$ftp->get($remote_file,$backup_dir) or dir "get failed", $ftp->message;

See what that returns

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hi Kevin,

I get this message:

Software error:
Get failed : File send OK.
No transfer to ABOR.

But when I check in c:\toto, I find nothing there copied.

Thanks.
 
have you tried turning passive mode off?

Passive => 0

I wish I had better suggestions but I never use the module and have little practicle experience to call upon to help in this situation.



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hi Kevin,

I tried it but it does not work but I try to look for another way to fix this issue.

Thanks a lot for your great help.
 
Hi Kevin again,

Have you another way to develop that without using NET::FTP?
Use only CGI scripting.

Thanks
 
I don't sorry. Other things to look at I guess would be firewall and proxy settings.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top