Access file attributes through Net::SFTP
If you want to access the modification time of a file on a remote server via Net::SFTP, use the following:
Net::SFTP.start('sftp.foo.com', 'user', :password => 'pass') do |sftp|
sftp.dir.glob('/remote/path', '**/*.rb') do |file|
puts file.attributes.mtime
end
end
You can also get these attributes as well:
- permissions
- uid
- gid
- size
- atime (time of last access)
mtime and atime return the time in number of seconds so pass this into Time.at to convert it to a Time object.
(Source: stackoverflow.com)