diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f44195ea..4621a323 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -19,6 +19,11 @@ Azure - Add ``mode`` kwarg to ``.url()`` to support creation of signed URLs for upload (`#1414`_) - Fix fetching user delegation key when custom domain is enabled (`#1418`_) +SFTP +---- + +- Add implementations of ``get_(modified|accessed)_time`` (`#1347`_) + .. _#1399: https://github.com/jschneier/django-storages/pull/1399 .. _#1381: https://github.com/jschneier/django-storages/pull/1381 .. _#1402: https://github.com/jschneier/django-storages/pull/1402 @@ -26,6 +31,7 @@ Azure .. _#1414: https://github.com/jschneier/django-storages/pull/1414 .. _#1417: https://github.com/jschneier/django-storages/pull/1417 .. _#1418: https://github.com/jschneier/django-storages/pull/1418 +.. _#1347: https://github.com/jschneier/django-storages/pull/1347 1.14.3 (2024-05-04) diff --git a/storages/backends/sftpstorage.py b/storages/backends/sftpstorage.py index 478235f6..ce76f749 100644 --- a/storages/backends/sftpstorage.py +++ b/storages/backends/sftpstorage.py @@ -9,10 +9,12 @@ import os import posixpath import stat +from datetime import datetime from urllib.parse import urljoin import paramiko from django.core.files.base import File +from django.utils import timezone from django.utils.deconstruct import deconstructible from paramiko.util import ClosingContextManager @@ -190,6 +192,18 @@ def size(self, name): remote_path = self._remote_path(name) return self.sftp.stat(remote_path).st_size + def get_accessed_time(self, name): + remote_path = self._remote_path(name) + utime = self.sftp.stat(remote_path).st_atime + ts = datetime.fromtimestamp(utime) + return timezone.make_aware(ts) if setting("USE_TZ") else ts + + def get_modified_time(self, name): + remote_path = self._remote_path(name) + utime = self.sftp.stat(remote_path).st_mtime + ts = datetime.fromtimestamp(utime) + return timezone.make_aware(ts) if setting("USE_TZ") else ts + def url(self, name): if self._base_url is None: raise ValueError("This file is not accessible via a URL.")