I am writing a code which need to get the file from remote server using Net::SFTP::Foreign
Perl module.
Here is the script.
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);
Remote server connection works fine. When I print $sftp->status
gives 0
as value which means its success.
Even in the Dumper I could see the files from the remote server in below format.
$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'
},
{
];
What I need is take out the modification time of each of the file. This needs to be printed like "filename, modification_time"
. How can I take these values from the Dumper.
According to the documentation of Net::SFTP::Foreign , there is a stat
method you can call to get a Net::SFTP::Foreign::Attributes instance:
my $attrs = $sftp->stat($path_or_fh)
And then ask for the mtime
, or the one you need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.