编译PERL脚本

时间:2015-10-22 20:15:29

标签: perl

已经有一段时间了,因为我已经完成了任何PERL编程,我正在开发一个项目,我需要连接到远程服务器并获取文件列表。该脚本是使用ActivePerl在Windows 2012服务器上开发的。

这是我从其他示例中汇总的脚本 -

#! /usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
use autodie;

use Net::SFTP::Foreign;

# US Server Configuration
use constant {
    HOST            => "samplehost",
    REMOTE_DIR      => "sample/remote",
    LOCAL_DIR       => "sample/local",
    PORT            => "3235",
    USER_NAME       => "username",
    PASSWORD        => "D%password",
    DEBUG           => "0",
};

my $stfp = Net::SFTP::Foreign->new (
    HOST,
    timeout         => 240,
    user            => USER_NAME,
    password        => PASSWORD,
    port            => PORT,
    autodie         => 1,
);

#
# List remote directory contents
#
my $remotefiles;
$remotefiles = $stfp->ls(REMOTE_DIR); 

#
# Loop through remote files and print each filename
#
foreach ($remotefiles){
    my $file = $_;
    my $filename = $file->{filename};
    if($filename ne "." && $filename ne ".."){
        print"the filename is $filename";
    }
}

编译时我收到错误 -

C:\development>perl ConvertPDFs.pl
password authentication not available, IO::Pty is not installed or failed to loa
d: Can't locate IO/Pty.pm in @INC (@INC contains: C:/Perl64/site/lib C:/Perl64/l
ib .) at C:/Perl64/site/lib/Net/SFTP/Foreign/Backend/Unix.pm line 256.
 at ConvertPDFs.pl line 20.

不确定是什么问题。

1 个答案:

答案 0 :(得分:1)

伪ttys是unix构造。如果一个模块需要IO :: Pty,它就不会在Windows上运行(尽管可能在cygwin上运行)。从好的方面来说,错误消息使它听起来像Net :: SFTP :: Foreign只使用IO :: Pty进行基于密码的身份验证,因此您可以通过切换到基于密钥的身份验证来避免此问题。

相关问题