Node.js copy remote file to server

前端 未结 3 2040
南旧
南旧 2020-12-11 20:33

Right now I\'m using this script in PHP. I pass it the image and size (large/medium/small) and if it\'s on my server it returns the link, otherwise it copies it from a remot

3条回答
  •  臣服心动
    2020-12-11 20:57

    If you can't use remote user's password for some reasons and need to use the identity key (RSA) for authentication, then programmatically executing the scp with child_process is good to go

    const { exec } = require('child_process');
    
    exec(`scp -i /path/to/key username@example.com:/remote/path/to/file /local/path`, 
         (error, stdout, stderr) => {
    
        if (error) {
          console.log(`There was an error ${error}`);
        }
    
          console.log(`The stdout is ${stdout}`);
          console.log(`The stderr is ${stderr}`);
    });
    

提交回复
热议问题