Reminder: If the user has write permissions for the current directory on the FTP server, they can call ftp_host.synchronize_times()
to set the time shift automatically.
If that's not possible or desired and the server reports timestamps in the same timezone as for the client, the time shift can be set with
ftp_host.set_time_shift(
round( (datetime.datetime.now() - datetime.datetime.utcnow()).seconds, -2 )
)
I thought about different approaches to make it even easier for users, for example, supporting a class attribute like initial_time_shift
("utc", "same_timezone_as_client", float) or a similar argument for the constructor. However, all these approaches add very little to the obvious implementations a user would/could do.
If the default time shift should be set on the class level, use
class MyFTPHost(ftputil.FTPHost):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
my_initial_time_shift = ...
self.set_time_shift(my_initial_time_shift)
If the default time shift should be set on the instance instance level, use
with FTPHost(...) as host:
my_initial_time_shift = ...
host.set_time_shift(my_initial_time_shift)
...