Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.

Commit

Permalink
Adds example of downloading file from server with progress bar in REA…
Browse files Browse the repository at this point in the history
…DME.md
  • Loading branch information
bompi88 committed Apr 29, 2017
1 parent 589a659 commit 032a618
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,42 @@ The high level client is an instance of `Client`, but it contains the high level

download a server file to local.

### Example with progress bar (download from server)

You can easily combine this module with the `progress` npm package, to get live progress data in your commandline interface. Example below:

```javascript
var scp2 = require('scp2');
var ProgressBar = require('progress');
var client = new scp2.Client();
var bar;
client.on('transfer', function(buf, downloaded, total) {
if (!bar) {
bar = new ProgressBar(' downloading [:bar] :rate/bps :percent :etas', {
complete: '=',
incomplete: ' ',
width: 20,
total: total
});
}
bar.tick(buf.length);
});
scp2.scp({
host: ...,
username: ...,
password: ...,
path: '/path/to/src/file'
}, '/path/to/dest/file', client, function(err) {
if (err) {
console.log(err);
}
// Do stuff with the downloaded file
});
```

## Events

Expand Down
1 change: 1 addition & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ Client.prototype.download = function(src, dest, callback) {
sftp.open(src, 'r', function(err, fd) {
sftp.fstat(fd, function(err, stats) {
var bufferSize = stats.size;
var bytesDownloaded = 0;

var sftp_readStream = sftp.createReadStream(src);
sftp_readStream.on('data', function(data) {
Expand Down

0 comments on commit 032a618

Please sign in to comment.