Comments (3)
If you want to copy multiple files, don't call sftp.end();
. You don't even have to wait for a file copy to finish before starting the next one.
Also: calling ws.end();
in your ReadableStream's 'end' handler is unnecessary since pipe() already takes care of all that.
Here's all you should need if you want to go the stream piping route:
c.sftp(function(err, sftp) {
if (err) throw err;
var files = ['.bashrc', 'test.sh',
'remotefile2', 'localfile2',
'remotefile3', 'localfile3'],
left = files.length / 2;
for (var i = 0; i < files.length; i += 2) {
var rs = sftp.createReadStream(files[i]),
ws = fs.createWriteStream(files[i + 1]);
ws.on('finish', function() {
if (--left === 0) {
console.log('SFTP :: All files transferred!');
c.end();
}
});
rs.on('error', function(err) { console.log('rs: ' + err); });
rs.pipe(ws);
}
});
If you have large files, you might benefit from parallel reads. In those cases you might want to use fastGet():
c.sftp(function(err, sftp) {
if (err) throw err;
var files = ['.bashrc', 'test.sh',
'remotefile2', 'localfile2',
'remotefile3', 'localfile3'],
left = files.length / 2;
for (var i = 0; i < files.length; i += 2) {
sftp.fastGet(files[i], files[i + 1], function(err) {
if (err) throw err;
if (--left === 0) {
console.log('SFTP :: All files transferred!');
c.end();
}
});
}
});
from ssh2.
Great. Thanks for the help. I have it working now. Is there any case that you would call sftp.end()
?
I will generally need to stream the files serially, but from multiple hosts (in parallel).
from ssh2.
Usually there is no real reason to end the sftp subsystem, you can always re-use it later.
from ssh2.
Related Issues (20)
- Can't connect "ignoring handled error" HOT 9
- any method to execute command after ssh connected. HOT 10
- Get remote port forwarding -R local port HOT 2
- Question: HTTPSAgent reuse HOT 3
- Execute ssh command inside a "for of" HOT 7
- Test code should be excluded from the published package HOT 1
- Question: Missing documentation in the code
- forwardIn binding to 127.0.0.1 instead HOT 2
- App stops on error timeout even if handled HOT 3
- Not building in Cloudflare Workers HOT 1
- Issue Connecting to MongoDB via SSH Tunnel in Node.js HOT 1
- Issue/Suggestion :- Adding of maxEventListner on all the event HOT 4
- allow server to connect to forwarded agent from client HOT 1
- ecdsa-sha2-nistp256 private key support
- "Key auth required before password auth" error when connecting HOT 2
- READDIR hangs indefinitely HOT 12
- Specify `node-gyp` as a dependency. HOT 3
- SSH Client fails handshake when using publickey method HOT 7
- pm2 restart 0 No data is returned HOT 4
- Cannot find the bashrc source configuration when using ssh2 connect to the server HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ssh2.