开发者

Different results for command line and CGI for perl web form script

开发者 https://www.devze.com 2023-01-28 13:31 出处:网络
The code for my sub: sub put_file { my($host, $placement_directory, $tar_directory, $filename, $user, $pass) = @_;

The code for my sub:

sub put_file
{
    my($host, $placement_directory, $tar_directory, $filename, $user, $pass) = @_;
    my $ftp = Net::FTP->new($host) or die "cannot connect to localhost";

    $ftp->login($user, $pass) or die "cannot log in";

    $ftp->cwd($placement_directory);
    print $tar_directory."/".$filename;
    $ftp->put("$tar_directory/$filename") or die "cannot put file ", $ftp->message;

    print "File has been placed \n";
}

So when this sub is called from a test script(that runs from command line) that uses the same config file and does all of the same things as the CGI script, no errors are found and the file is placed correctly. When the sub is called from my CGI script the script will output the $tar_directory."/".$filename but not "File has been placed \n" and the ftp->message outputs "cannot put file Directory successfully changed." Which seems to come from the cwd line before it.

Other info: I have tried running the test script as multiple users with the same result. I use strict and warnings. The tar file that is being moved is created by the script.

I'm new to perl so any advice is helpful because I'm stuck on this and开发者_运维百科 cant find any help using the power of The Google.


Just a guess. Your ftp->put is failing, triggering the die. Unless you have:

use CGI::Carp qw(carpout fatalsToBrowser);

you won't see the die message in your browser. Since you died, you don't see the final print statement either.

Check your webserver log for the die output, or just change "die" to "print".


Net::FTP can put() from a filehandle as well as a file name:

open my $fh, '<', $tar_directory . '/' . $filename or die "Could not open file: $!";
$ftp->put($fh, $filename) or die "cannot put file ", $ftp->message;

If the problem is on your side then the open should fail and you should get an error message of some kind that will, hopefully, tell you what is wrong; if the problem is on the remote side then the put should fail and you'll see the same thing you'r seeing now.

That $ftp->message only has the success message from the cwd indicates that everything is fine on the remote side and the put isn't even reaching the remote server.

0

精彩评论

暂无评论...
验证码 换一张
取 消