Copy files from remote server to local node js application folder using node-ssh

214 views Asked by At

Hi I am trying to copy zip file from remote server to local node js folder . i tried like below but unable to copy file.

const { NodeSSH } = require('node-ssh');
const ssh = new NodeSSH();

const sshConfig = {
 host: config.host,
 port: 22,
 username: config.hostname,
 password: config.hostpassword,
};

const localZipPath = `./uploads/${zipFileName}`;
const remoteZipPath = path.posix.join(remoteDirectory, zipFileName);
        
const cmd = `scp -r ${remoteZipPath} ${localZipPath}`;
console.log(cmd);

const copyresult = await ssh.execCommand(cmd);
console.log(copyresult);

from the above scp command its copying to root directory of that remote server itself not to local node js uploads folder.Please help me how can i copy file from remote to local.

I can't user ssh.getFile() or ssh.putFile() i don't have necessary permissions to sftp connection

0

There are 0 answers