You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ssh2 does not set mtime/atime (scp_send64, setstat, fsetstat) #103
scp_send64(self, path, int mode, libssh2_uint64_t size, time_t mtime, time_t atime)
But mtime and atime seem to be ignored. I tried copying from the examples, but it still won't work.
My authentication method is by the way userauth_password.
It did work with paramiko, so it shouldn't be an issue with the ssh server.
By the way: I would consider to work around this using setstat(path, attrs), but I'm not sure how I would have to create the SFTPAttributes object. It would be nice to have an example or more documentation on that.
mtime and atime are passed onto libssh2 - whether they do anything depends on libssh2. SFTPAttributes is a python class typical python code to create object and set attributes.
I just took a peek into the source code. I didn't find anything suspicious yet.
Looking at the manpage, it should be working...
No issues reported on the GitHub project either...
It would be nice if you could confirm that it is a pure ssh2 library problem. I could open an issue over there then.
I also tried the sftp_handle.fsetstat, but that also doesn't seem to work.
Just in case, I also used a vm with mx linux using python 3.7, but it's also not working over there (sent file from vm to local pc).
Looks that I can't import the three attributes. Are you sure about the location "ssh2.sftp"?
EDIT: The import shows an error, but it does compile. Testing right now.
This still doesn't work.
Then I tried the code above. It does work, but I will have to make one more network transaction. Uploading multiple files will slow down heavily.
Setting attributes individually from an OS stat works fine, attr.flags just need to be set correctly depending on what is being changed by sftp.setstat, meaning need LIBSSH2_SFTP_ATTR_ACMODTIME set if changing times and so on.
Setting time with scp_send64 have not tested in C yet, if have some example code that would be really useful. There is an scp example in libssh2/examples in the repository.
C code to reproduce scp behaviour would be great, so can debug and raise issue with libssh2, or python code to see if the issue is in ssh2-python or libssh2.
Anyways, I can confirm fsetstat and setstat working. The access and modification time is set correctly.
There is a strange thing though...
It seems I can import the necessary three flags from ssh2.sftp. Pycharm says that it can't find their references. Looking into the sftp.py, there is no such flags. I suppose they are inside sftp.c and sftp.pyx...
The ATTR flags are new in 0.23.0. The IDE probably needs to re-index the new package version. There is no sftp.py in ssh2-python, the imported module is a dynamic library (.so | ldd).
Will try to reproduce in C, not very high priority atm.
This is likely a result of a default umask that does not allow setting atime/mtime on creation. Hence why a separate setstat subsequently works. As default umask is system specific, nothing to be done.
Activity
hakaishi commentedon Aug 13, 2020
Btw.: Using python 3.8.2 on Ubuntu 20.04
pkittenis commentedon Aug 14, 2020
Hey,
mtimeandatimeare passed onto libssh2 - whether they do anything depends on libssh2.SFTPAttributesis a python class typical python code to create object and set attributes.hakaishi commentedon Aug 14, 2020
I just took a peek into the source code. I didn't find anything suspicious yet.
Looking at the manpage, it should be working...
No issues reported on the GitHub project either...
It would be nice if you could confirm that it is a pure ssh2 library problem. I could open an issue over there then.
hakaishi commentedon Aug 14, 2020
I've never worked with cdef and the like.
The function definitions look like I could simply do things like
and so on...
It would be convenient if I could simply initialize the object using the stat result of the file 😇
hakaishi commentedon Aug 17, 2020
I tried the following (with full paths though):
first print with local file says: ".bashrc 2019-07-08 08:10:56.616019"
second print with remote file says: "2020-08-17 22:38:00 2020-08-17 22:45:40"
EDIT: I also tried it with relative paths (hard coded) with the same negative result
hakaishi commentedon Aug 18, 2020
I also tried the sftp_handle.fsetstat, but that also doesn't seem to work.
Just in case, I also used a vm with mx linux using python 3.7, but it's also not working over there (sent file from vm to local pc).
[-]scp_send64 does not set mtime/atime[/-][+]ssh2 does not set mtime/atime (scp_send64, setstat, fsetstat)[/+]pkittenis commentedon Aug 18, 2020
Will try and reproduce in C when have some time, not high priority atm.
pkittenis commentedon Oct 25, 2020
With
0.23.0try:hakaishi commentedon Oct 25, 2020
Looks that I can't import the three attributes. Are you sure about the location "ssh2.sftp"?
EDIT: The import shows an error, but it does compile. Testing right now.
hakaishi commentedon Oct 25, 2020
I tried the following first (using the sftp_handle):
This still doesn't work.
Then I tried the code above. It does work, but I will have to make one more network transaction. Uploading multiple files will slow down heavily.
EDIT:
This works too:
pkittenis commentedon Oct 27, 2020
SFTPAttributesdoes not take arguments.Setting attributes individually from an OS stat works fine,
attr.flagsjust need to be set correctly depending on what is being changed bysftp.setstat, meaning needLIBSSH2_SFTP_ATTR_ACMODTIMEset if changing times and so on.Setting time with
scp_send64have not tested in C yet, if have some example code that would be really useful. There is an scp example inlibssh2/examplesin the repository.hakaishi commentedon Oct 27, 2020
If you mean Python code, I might manage something tomorrow.
What I meant to say earlier is that conn.setstat works while sftp_handle.fsetstat doesn't.
pkittenis commentedon Oct 27, 2020
The python code shown for
fsetstatdoes not set theACMODTIMEflag.Should be:
C code to reproduce scp behaviour would be great, so can debug and raise issue with libssh2, or python code to see if the issue is in ssh2-python or libssh2.
hakaishi commentedon Oct 27, 2020
Ah! I misplaced a flag! 😅
I'm not too familiar with C, but I'll see what I can do.
hakaishi commentedon Oct 28, 2020
My python code would look like this (time stamps are ignored though):
As for the C code... I didn't got to it, but this might help: https://github.com/libssh2/libssh2/blob/master/example/scp_write.c
I found some docu over here
hakaishi commentedon Oct 29, 2020
Anyways, I can confirm fsetstat and setstat working. The access and modification time is set correctly.
There is a strange thing though...
It seems I can import the necessary three flags from ssh2.sftp. Pycharm says that it can't find their references. Looking into the sftp.py, there is no such flags. I suppose they are inside sftp.c and sftp.pyx...
pkittenis commentedon Nov 8, 2020
The
ATTRflags are new in0.23.0. The IDE probably needs to re-index the new package version. There is nosftp.pyin ssh2-python, the imported module is a dynamic library (.so | ldd).Will try to reproduce in C, not very high priority atm.
pkittenis commentedon Jan 12, 2025
This is likely a result of a default umask that does not allow setting atime/mtime on creation. Hence why a separate setstat subsequently works. As default umask is system specific, nothing to be done.