1

I'm using the node-ssh2 module to copy files to remote servers. In general I don't have the ability to change the default umask on the servers. But I need the remote file's mode to be 0666 after it's copied.

If I set it first locally and then just run scp -p <localfile> <remote> it works fine, preserving the 0666 permission. How do I do this with node.js? I've tried using node-ssh2 and starting an sftp session. Then I do sftp.fastPut but the permissions are always set to 0644 on the server.

As I said I'm currently using the node-ssh2 module and I'd like to stick with that but if I need use something different that is ok.

Sean Lynch
  • 2,852
  • 4
  • 32
  • 46

1 Answers1

1

Specify it in the options argument for fastPut:

sftp.fastPut( 'local_path', 'remote_path', { mode: 0666 }, callback );
Paul
  • 139,544
  • 27
  • 275
  • 264
  • I've tried that and it doesn't work. It seems that the mode is not an option for fastPut. https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md – Sean Lynch Jan 15 '16 at 16:19
  • @SeanLynch Oh, my bad. Sorry, I'll delete this answer in a minute if I can't find a proper solution to edit it. – Paul Jan 15 '16 at 16:21
  • No worries. I thought that would work too. I have also tried `sftp.createWriteStream(, {mode: 0666})`. The `createWriteStream` function *does* take the mode option, but it get's overridden by the server and ends up as 0644. – Sean Lynch Jan 15 '16 at 16:43
  • Here 'remote_path' means 'remote_path/file_name'. Error is thrown without file name. – Gagan Aug 18 '21 at 11:51