perl - 为什么 Perl 的 Net::FTP 不上传我的文件?

标签 perl ftp

我正在尝试通过 Net::FTP 上传多个文件和珀尔。有没有人这样做过,因为我下面的基本脚本都失败了?

use Net::FTP;
use File::Basename;

my $ftp;
my $host ='56.309.24.2';
my $user ='user';
my $pw   ='pass';

my $file ='097360718843.jpeg';
my $path ='public_html/uploaded/product_images';

chomp($host,$user,$pw,$path, $file);

$ftp=Net::FTP->new($host) or die "could not login";
$ftp->login($user,$pw) or die "could not login";
$ftp->cwd($path) or die "could not cwd $path";
$ftp->ls;
$ftp->put($file) or die "could not put $file";
$ftp->site("chmod 600 " . basename($file));

这是传输日志:

Net::FTP>>> 
Net::FTP(2.75) 
Net::FTP>>> Exporter(5.58) 
Net::FTP>>> 
Net::Cmd(2.26) 
Net::FTP>>> IO::Socket::INET(1.27) 
Net::FTP>>> IO::Socket(1.28) 
Net::FTP>>> IO::Handle(1.24) 
Net::FTP=GLOB(0x180c6a8)<<< 220---------- Welcome to Pure-FTPd [TLS] ---------- 
Net::FTP=GLOB(0x180c6a8)<<< 220-You are user number 1 of 50 allowed. 
Net::FTP=GLOB(0x180c6a8)<<< 220-Local time is now 16:19. Server port: 21. 
Net::FTP=GLOB(0x180c6a8)<<< 220-IPv6 connections are also welcome on this server. 
Net::FTP=GLOB(0x180c6a8)<<< 220 You will be disconnected after 15 minutes of inactivity.
Net::FTP=GLOB(0x180c648)>>> user user_name 
Net::FTP=GLOB(0x180c648)<<< 331 User user_name OK. Password required 
Net::FTP=GLOB(0x180c648)>>> PASS .... 
Net::FTP=GLOB(0x180c648)<<< 230-User user_name has group access to: user_name wheel 
Net::FTP=GLOB(0x180c648)<<< 230 OK. Current restricted directory is / 
Net::FTP=GLOB(0x180c648)>>> CWD public_html/uploaded/product_images/ 
Net::FTP=GLOB(0x180c648)<<< 250 OK. Current directory is /public_html/uploaded/product_images 
Net::FTP=GLOB(0x180c648)>>> PORT 192,168,1,10,200,38 
Net::FTP=GLOB(0x180c648)<<< 200 PORT command successful
Net::FTP=GLOB(0x180c648)>>> NLST 
Net::FTP=GLOB(0x180c648)<<< 150 Connecting to port 50703 
Net::FTP=GLOB(0x180c648)<<< 226-Options: -a 
Net::FTP=GLOB(0x180c648)<<< 226 Output truncated to 2000 matches 
Net::FTP=GLOB(0x180c648)>>> ALLO 7903 
Net::FTP=GLOB(0x180c648)<<< 200 Zzz... 
Net::FTP=GLOB(0x180c648)>>> PORT 192,168,1,10,200,39 
Net::FTP=GLOB(0x180c648)<<< 200 PORT command successful 
Net::FTP=GLOB(0x180c648)>>> STOR 097360718843.jpeg 
Net::FTP=GLOB(0x180c648)<<< 150 Connecting to port 50704 
Net::FTP=GLOB(0x180c648)<<< 226-File successfully transferred
Net::FTP=GLOB(0x180c648)<<< 226 0.381 seconds (measured here), 20.21 Kbytes per second 
Net::FTP=GLOB(0x180c648)>>> SITE chmod 600 097360718843.jpeg 
Net::FTP=GLOB(0x180c648)<<< 200 Permissions changed on 097360718843.jpeg

最佳答案

使用

my $ftp = Net::FTP->new($host, Debug => 1) 
    or die "Could not create FTP object: $@";

其他良好实践:

  • 确保您拥有

    use strict;
    use warnings;
    
  • 不要在需要变量之前声明变量。

  • 在错误消息中包含错误。

简而言之,尝试以下脚本:

#!/usr/bin/perl

use strict;
use warnings;

use Net::FTP;

my $host ='56.309.24.2';
my $user ='user';
my $pw   ='pass';

my $file ='097360718843.jpeg';
my $path ='public_html/uploaded/product_images';

my $ftp = Net::FTP->new($host, Debug => 1) 
    or die "Could not connect to '$host': $@";

$ftp->login($user, $pw) 
    or die sprintf "Could not login: %s", $ftp->message;

$ftp->cwd($path) 
    or die sprintf "Could not login: %s", $ftp->message;

$ftp->ls;

$ftp->binary;

$ftp->put($file) 
    or die die sprintf "Could not login: %s", $ftp->message;

$ftp->site("chmod 600 $file");

关于perl - 为什么 Perl 的 Net::FTP 不上传我的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1290143/

相关文章:

azure - FTP文件上传错误: An exception occurred during a WebClient request. InnerException : This method is not supported.(参数 'value')

c++ - 编程 ftp : how to abort file transfer?

mysql - proftpd通过mysql和FTP用户的web管理

perl - 如何使 ExtUtils::Manifest 包含空目录?

python - 在 Python 中的 re.sub 中获取组匹配

PHP:处理从 Perl 发送的 POST 请求

java - 如何用Netty搭建FTP服务器?

perl - 我可以对要迭代的常量进行分组吗?

linux - 如果我安装了 SIGCHLD 处理程序,对特定 pid 的 *blocking* 等待是否仍然有效?

python - 使用 Python 从 ftp 下载