vlad.rad
vlad.rad

Reputation: 1083

paramiko - How can I refresh the modified date of a file on the SFTP server automatically?

I have a file on the SFTP server that should be imported with paramiko package on certain conditions. Until these conditions aren't fulfilled, this file should stay on the server unimported, but its modified date shoud be updated, so that this date should be always bigger than the time, at which file was checked by my import program.

I read the documentation for the package but didn't found any function that could do this.

Upvotes: 0

Views: 1136

Answers (3)

Martin Prikryl
Martin Prikryl

Reputation: 202168

There's the utime method:

 utime(path, times)

Set the access and modified times of the file specified by path. If times is None, then the file’s access and modified times are set to the current time. Otherwise, times must be a 2-tuple of numbers, of the form (atime, mtime), which is used to set the access and modified times, respectively.

Upvotes: 2

Ellioh
Ellioh

Reputation: 5330

I would try opening the file in append mode ("a") and closing it immediately.

Upvotes: 0

vlad.rad
vlad.rad

Reputation: 1083

This can be done with copying the file from the SFTP to the local host, removing the file from the SFTP and copying it again to the SFTP.

So,

  1. get(remotepath, localpath, callback=None)
  2. remove(path)
  3. put(localpath, remotepath, callback=None, confirm=True)

If anyone has another idea, please share your knowledge!

Upvotes: 0

Related Questions