Is there a way to get the date changed from the Net :: SSH or NET :: SFTP commands in ruby?

Is there an easy way to get the file modification date using Net :: SFTP?

It would be nice to be able to do this:

Net::SFTP.start('some_server') do |sftp|
  sftp.dir.glob('*').each do |file|
    puts file.mtime
  end
end

But this is impossible (as far as I know).

Burns.

+3
source share
1 answer

Your sample code almost exists, you just need to use file.attributes.mtimewhere you have it file.mtime.

In addition, I assume that the code in the question was just an example, but to execute it, you also need to pass the username and password to startand pass the path, as well as the template to glob. So a working example:

Net::SFTP.start('some_server', 'mike', :password => 'secret') do |sftp|
  sftp.dir.glob('.', '*').each do |file|
    puts file.attributes.mtime
  end
end

, mtime, , Time.at Time.

, , :

  • permissions
  • uid
  • gid
  • size
  • atime ( )
+9

Source: https://habr.com/ru/post/1742005/


All Articles