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

Commit 9e47556

Browse files
committed
Adds example of downloading file from server with progress bar in README.md
1 parent 589a659 commit 9e47556

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,42 @@ The high level client is an instance of `Client`, but it contains the high level
191191

192192
download a server file to local.
193193

194+
### Example with progress bar (download from server)
195+
196+
You can easily combine this module with the `progress` npm package, to get live progress data in your commandline interface. Example below:
197+
198+
```javascript
199+
var scp2 = require('scp2');
200+
var ProgressBar = require('progress');
201+
202+
var client = new scp2.Client();
203+
var bar;
204+
205+
client.on('transfer', function(buf, downloaded, total) {
206+
if (!bar) {
207+
bar = new ProgressBar(' downloading [:bar] :rate/bps :percent :etas', {
208+
complete: '=',
209+
incomplete: ' ',
210+
width: 20,
211+
total: total
212+
});
213+
}
214+
bar.tick(buf.length);
215+
});
216+
217+
scp2.scp({
218+
host: ...,
219+
username: ...,
220+
password: ...,
221+
path: '/path/to/src/file'
222+
}, '/path/to/dest/file', client, function(err) {
223+
if (err) {
224+
console.log(err);
225+
}
226+
227+
// Do stuff with the downloaded file
228+
});
229+
```
194230

195231
## Events
196232

0 commit comments

Comments
 (0)