Remote-ftp: Remote FTP overwrites file permissions to 0666

Created on 9 Dec 2016  路  15Comments  路  Source: icetee/remote-ftp

Maybe I'm just dumb and this is a config setting, but I swear this didnt use to be the case. All of a sudden on my window's atom, any time I use atom ftp to save a file on a remote machine, that files permissions get changed to 666 (-rw-rw-rw-. Its super annoying to have to ssh in and change them back afterwards :(

bug

Most helpful comment

If anyone submitted a PR i'd be happy :)

All 15 comments

I also have experienced this problem recently, its not just you.

I am on a mac. Permissions are being changed when a file is saved/uploaded. the default behavior should be for files being edited to upload with the same permissions they were before. I am seeing the issue on MacOS

I am on Linux and use sftp connection. Same problem.

Mac. Same problem: changes from 755 to 644

Same on Windows.. Wasn't this way before.

I've encountered the same problem on Windows; while saving a file that is 755, it goes to 675.

Anybody got this figured out? It is still an issue

The problem lies here in the new undocumented filePermission option for the .ftpconfig.
https://github.com/mgrenier/remote-ftp/blame/a1abd216ee276a9ff484f74b780620c8df442d42/lib/client.js#L389

In my opinion, the correct behavior should be to keep the original permissions if the option isn't set and only overwrite them when the option is set in the .ftpconfig.

Simply removing options argument from createWriteStream function call from https://github.com/mgrenier/remote-ftp/blob/master/lib/connectors/sftp.js#L318 did not work. ssh2-stream will set some permission anyway (https://github.com/mscdex/ssh2-streams/blob/master/lib/sftp.js#L2858).

I'm not sure this is the best solution, but it works for me:

Insert the following code fragments at https://github.com/mgrenier/remote-ftp/blob/master/lib/connectors/sftp.js#L317:

self.sftp.stat(remotePath, function(err, attrs) {
    if (err) {
        atom.notifications.addError("Cannot get the file permission on the server. Use default permission.");

    } else {
        options.mode = attrs.mode;

    }

and then put the following at https://github.com/mgrenier/remote-ftp/blob/master/lib/connectors/sftp.js#L370:

});

In summary, every time Remote-FTP saves a file, it tries to get the file permission from the server (self.sftp.stat call), and use it for createWriteStream call. If self.sftp.stat fails, it follows the current behavior. I'm not a node.js guy, so I'm not sure this is a right way to solve this problem.

I really love this package, so I hope someone can work on this issue! ;-)

I confirm, this makes the stuff.
A grand thank to you

naoya-i - I would push this commit if I were you it solved the issue. Even if its not perfect its better than the current implementation.

Cheers.

If anyone submitted a PR i'd be happy :)

Sorry was busy on others projects -- thanks to you for making things going on.
666 is not secure as 644 would be as standard imho.
Else I'm usually working with bash cgi and need +x for, is why I was not happy with last decision to go on 666 - the devil ....

It's 0664 as default for new files now.

See https://github.com/mgrenier/remote-ftp/blob/5d4580faa7c9be381a1f1b515dc9eeaad83bd165/lib/connectors/sftp.js#L321

(Aaaand there i spotted a double semicolon in my own code -_-)

Excellent, have a nice evening

Was this page helpful?
0 / 5 - 0 ratings

Related issues

krkmzugur picture krkmzugur  路  7Comments

lukecywon picture lukecywon  路  6Comments

fausto160792 picture fausto160792  路  7Comments

xabispacebiker picture xabispacebiker  路  5Comments

Darkspirit picture Darkspirit  路  4Comments