我在Perl中很新,所以請試着理解我。 我有一個.txt文件中定義了一些行是這樣的:使用Perl獲取一個.txt文件,併爲該文件中的每一行做點什麼
doc1.20131010.zip
doc2.20131010.zip
doc3.20131010.zip
doc4.20131010.zip
我做了這個代碼:
#! /usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
use autodie;
use Net::SFTP::Attributes;
use Net::SFTP;
use constant {
HOST => "x.x.x.x",
USER_NAME => "sftptest",
PASSWORD => "**********",
DEBUG => "0",
};
my $REMOTE_DIR = "IN";
my $LOCAL_DIR = "/home/rec";
my $sftp = Net::SFTP->new (
HOST,
timeout => 240,
user => USER_NAME,
password => PASSWORD,
autodie => 1,
);
#
# Fetch Files
#
#my $res = $sftp->ls($REMOTE_DIR,sub { print $_[0]{longname}, "\n" });
#print "$res";
my $ls = $sftp->ls($REMOTE_DIR)
or die "ls failed: " . $sftp->error;
open my $fh, '>', '/home/rec/listing' or die "unable to create file: $!";
print $fh $_->{filename}, "\n" for @$ls;
close $fh;
open F, "</home/docs/listing";
for my $line (<F>)
{
#print "$line";
$sftp->get("$line","$line") ;
}
現在,當我運行上面的代碼就應該給我列出上面的文件,而不是我得到這個:
Couldn't stat remote file: No such file or directory at ./r.pl line 40.
答案是在40行 –
是的,但請告訴我更多,我不知道該看什麼。謝謝 – ion
我想告訴你,但不知道第40行的內容是什麼 –