使用 Perl::FTP 时,我应该在主机字段中输入什么来连接到网络上连接的本地计算机

发布于 2024-12-31 22:03:52 字数 450 浏览 1 评论 0原文

我正在 Perl 中使用 Net::FTP 进行一些文件传输。当我运行以下代码时:-

使用 IP 地址是否存在任何问题?我在主机字段中提供此信息是否正确?

use strict;          
use Net::FTP;

my $host = "10.77.69.124";
my $user = "administrator";
my $password = "Password";

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

该代码无法连接到远程主机。为什么会出现这种情况?这不应该与 $host 中提供的 IP 地址一起使用吗?

I am using the Net::FTP in perl to do some file transfers. when I run the following code :-

Are there any issues with using the IP address ? Am I correct in providing this in the host field ?

use strict;          
use Net::FTP;

my $host = "10.77.69.124";
my $user = "administrator";
my $password = "Password";

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

The code is not able to connect to the remote host. Why is this happening ? Shouldn't this work with the IP address provided in the $host ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风为裳 2025-01-07 22:03:52

Net::FTP 的构造函数允许您传递单个标量值或主机数组来尝试。该字段的值应与 IO 中的 PeerAddr 相同: :Socket::INET主机名或 IP 地址)。

通过指定“调试”来仔细查看发生的情况。如果您位于防火墙或 NAT 设置后面,您可能还应该将 Passive 设置为非零值,并确保通过打印 $@ 来检查构造函数是否失败。

my $ftp = Net::FTP->new(Host=>$host, Debug=>1, Passive=>1) || die $@;

如果构造函数成功,您可能需要检查其他方法是否失败:

$ftp->login($user, $pass) || die $ftp->message;
$ftp->cwd($path) || die $ftp->message;

顺便说一句:如果您不确定是否使用了正确的主机参数,您可以询问 Net::FTP 它尝试连接到哪个主机:

print $ftp->host, "\n";

如果这仍然不起作用,请提供您的应用程序的详细输出。

希望这有帮助。

The constructor of Net::FTP allows you to pass a single scalar value or an array of hosts to try. The value of this field should be the same as the PeerAddr from IO::Socket::INET (either a hostname or an ip address).

Have a closer look at what is happening by specifying Debug. If you are behind a firewall or a NAT setup, you should probably also set Passive to a non-zero value and make sure to check if the constructor failed by printing out $@.

my $ftp = Net::FTP->new(Host=>$host, Debug=>1, Passive=>1) || die $@;

If the constructor succeeded, you might want to check if any of the other methods fail:

$ftp->login($user, $pass) || die $ftp->message;
$ftp->cwd($path) || die $ftp->message;

By the way: If you are unsure if you've used the correct host parameter, you can ask Net::FTP which host it tried to connect to:

print $ftp->host, "\n";

If this still doesn't work, please provide a detailed output of your application.

Hope this helps.

同展鸳鸯锦 2025-01-07 22:03:52

首先确保您可以到达远程端:

从命令行使用 telnet(在 Linux 和 Windows 上也可用,但语法不同)

telnet host 21

如果您无法从命令行连接,请检查防火墙规则或可能是您的 FTP 服务器在不同的端口上运行?

如果您能够连接,请尝试使用普通 FTP 命令登录:

USER [email protected]
PASS yourpassword

这将使用 ACTIVE ftp 连接到远程。这是老办法。

现在大多数 ftp 服务器都使用 PASSIVE ftp。要测试尝试这个命令(从linux命令行),

ftp -v -p host

在perl中你可以这样使用被动模式:

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

我希望这会对你有所帮助。

First be sure that you can reach the remote side:

From command line use telnet (available on linux and windows too, a it different in syntax)

telnet host 21

If you are not able to connect the from commandline, check for firewall rules or maybe your FTP server running on different port?

If you are able to connect try out login with plain FTP commands:

USER [email protected]
PASS yourpassword

This will use ACTIVE ftp connection to the remote. This is the old way.

Nowadays most ftp server use PASSIVE ftp. To test try this command out (from linux commandline)

ftp -v -p host

In perl you could use passive mode this way:

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

I hope this will help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文