perl - 使用 Net::SFTP::Foreign Perl 模块在屏幕上打印远程服务器 FILENAME、MTIME
问题描述
我正在编写一个需要使用Net::SFTP::Foreign
Perl 模块从远程服务器获取文件的代码。
这是脚本。
my $sftp = Net::SFTP::Foreign->new(
host=>$host,
user=>$user,
password=>$pass
);
$sftp->die_on_error("Unable to establish SFTP connection");
$sftp->setcwd($path) or die "unable to change cwd: " . $sftp->error;
my @files = $sftp->ls($path);
print Dumper(\@files);
远程服务器连接工作正常。当我打印$sftp->status
出0
价值时,这意味着它的成功。
即使在 Dumper 中,我也可以看到来自远程服务器的以下格式的文件。
$VAR1 = [
{
'filename' => 'script.py',
'a' => bless( {
'perm' => 33204,
'size' => 25,
'gid' => 1001,
'flags' => 15,
'mtime' => 1571147796,
'uid' => 1001,
'atime' => 1571655805
}, 'Net::SFTP::Foreign::Attributes' ),
'longname' => '-rw-rw-r-- 1 test_vk test_vk 25 Oct 15 13:56 script.py'
},
{
'a' => bless( {
'flags' => 15,
'mtime' => 1571417934,
'atime' => 1571655769,
'uid' => 1001,
'gid' => 1001,
'size' => 369,
'perm' => 33204
}, 'Net::SFTP::Foreign::Attributes' ),
'longname' => '-rw-rw-r-- 1 test_vk test_vk 369 Oct 18 16:58 script.pl',
'filename' => 'script.pl'
},
{
'longname' => '-rw-r--r-- 1 root root 0 Oct 30 04:32 script123.pl',
'a' => bless( {
'gid' => 0,
'size' => 0,
'perm' => 33188,
'flags' => 15,
'mtime' => 1572409960,
'uid' => 0,
'atime' => 1572409960
}, 'Net::SFTP::Foreign::Attributes' ),
'filename' => 'script123.pl'
},
{
];
我需要的是取出每个文件的修改时间。这需要像"filename, modification_time"
. 如何从 Dumper 中获取这些值。
解决方案
根据Net::SFTP::Foreign的文档,您可以调用一个stat
方法来获取Net::SFTP::Foreign::Attributes实例:
my $attrs = $sftp->stat($path_or_fh)
然后询问mtime
, 或你需要的那个。
推荐阅读
- migration - Microfocus ALM:如何使用分析视图中的 SQL 查询导出测试用例的附件
- microsoft-graph-api - 确定 Teams 会议是否开始
- android - 无法使用意图传递对象
- firebase - 如何在 Flutter 中将资产上传到 FirebaseStorage?
- jquery - 如何通过文件 .js 获取 jquery.data(element).actions 的结果?
- html - ajax调用后单击功能/连接未来元素不起作用
- azure - 如何使用 Power Shell 脚本从 Key Vault 获取证书?
- itext7 - iText7 翻转文本 - 错误?
- java - 打开一个片段,用能够返回的方式替换 nav_host
- eclipse - 运行功能时黄瓜找不到步骤