Preserve mtime when using FTP?

I am using Net::FTP to copy files, but the file stats are not
preserved. In particular, I would like to preserve mtime (time of last
modification).

There is an FTP mtime method that can get the mtime of the remote file.

Is there any way to preserve or set mtime, or is there a different
protocol or library I should use?

Thanks,
Greg

greg wrote:

I am using Net::FTP to copy files, but the file stats are not
preserved. In particular, I would like to preserve mtime (time of last
modification).

There is an FTP mtime method that can get the mtime of the remote file.

But FTP can’t set the mtime on remote files, it can only retrieve it.

Is there any way to preserve or set mtime, or is there a different
protocol or library I should use?

The FTP protocol doesn’t do this, anywhere, on any platform, at all.
Therefore Ruby FTP doesn’t do it either.

Have you considered using an ssh or sftp transaction instead?

Unless I am mistaken I don’t think sftp will preserve the file
metadata. I don’t know how ssh would either. sftp and ftp use
File.open( local_path, “wb” ) { |f| f.write contents }

After looking through the FileUtils source which can preserve metadata,
I see it just uses File.utime to set the metadata, so that is what I
will try.

greg wrote:

Unless I am mistaken I don’t think sftp will preserve the file
metadata. I don’t know how ssh would either. sftp and ftp use
File.open( local_path, “wb” ) { |f| f.write contents }

Not the sftp I’m thinking of. In any case, you can use ssh to force a
reset
of the destination file state using data passed from the source. I think
this is how “rsync” does it.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs