Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set stats of uploaded file either via setstat or open/write #22

Closed
robogeek opened this issue Jan 27, 2013 · 6 comments
Closed

Comments

@robogeek
Copy link

I'm writing a tool to synchronize files to a server (node-ssh2sync) and one thing I want is to set the file create/access/modify times to match those on my laptop.

The attributes object isn't documented .. so I'm guessing that the fields required would be the same as returned by fs.stat or sftp.stat.

Hence,

sftp.mkdir(remotedir, {
                                ctime: statz.ctime,
                                atime: statz.atime,
                                mtime: statz.mtime
                            }, function(err) {

or

sftp.setstat(remotedir, {
                                        ctime: statz.ctime,
                                        atime: statz.atime,
                                        mtime: statz.mtime
                                    }, function(err) {
                                        doit(root_local, root_remote, sftp, thepath, function(err) {
                                            if (err) cb(err); else cb();
                                        });
                                    });

Visit my repository to see the exact script ..

@mscdex
Copy link
Owner

mscdex commented Jan 27, 2013

Yes, this was recently fixed in the readme recently and should be in the latest version on npm.

It's not the same attributes as fs.Stats though (see here).

@mscdex mscdex closed this as completed Jan 27, 2013
@robogeek
Copy link
Author

Okay.. so that means it's the "number of miliseconds since Jan 1 1970"? I tried this following and got file dates all over the map, from 1972 to 2034 .. That is, fs.stat returns a Date object, and Date.getTime() returns the number of milliseconds since the Epoch. Am I understanding this up right?

ctime: statz.ctime.getTime(),
atime: statz.atime.getTime(),
mtime: statz.mtime.getTime()

@mscdex
Copy link
Owner

mscdex commented Jan 28, 2013

There is no ctime. atime and mtime are UNIX timestamps, so it would be number of seconds since 1/1/1970.

So you want getTime() / 1000 instead.

@mscdex
Copy link
Owner

mscdex commented Jan 28, 2013

Ok, I've pushed some changes to allow for Date instances in ATTRS objects. I have also added utimes/futimes methods to make things simpler.

@mscdex
Copy link
Owner

mscdex commented Feb 12, 2013

Can you please try with the latest version now and see if setting atime and mtime work for you now?

@mscdex mscdex reopened this Feb 12, 2013
@robogeek
Copy link
Author

Yes, I just updated and reran my code and it works fine.

The tool is here:- https://github.com/robogeek/node-ssh2sync

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants