I think the simplest solution would be to use the methods downloadDir() and upload() ssh2-sftp-client itself to download the folder and upload to a new folder, which may be on another server.
Below is an example if the two folders are on the same server, if they are two different server folders you will have to make two connections with sftp.connect()
const sftp = require('ssh-sftp-client');
const config = {
host: {
host: host
username: username
password: password,
}
folder: folder // pasta no servidor a ser baixada
local: local // pasta no projeto
bkp: bkp // pasta de backup
}
await sftp.connect(config.host);
await sftp.downloadDir(config.folder, config.local);
await sftp.uploadDir(config.local, config.bkp);
await sftp.end();
You can also use libraries to compress the directory, such as in this example
Using ssh2-sftp-client, I did a project similar to yours, but in my case received a folder with . xls files from an A server to turn into . csv and send to a B server.
Project link
Welcome to Sopt. Try to add the examples to the reply, leaving the links only for additional information.
– tvdias
I updated the answer, I think the example would solve the problem.
– renandmc