sftp-push-sync 1.0.3 ā 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/sftp-push-sync.mjs +21 -16
- package/package.json +1 -1
package/bin/sftp-push-sync.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
** sync-sftp.mjs - SFTP Syncronisations Tool
|
|
4
4
|
*
|
|
5
5
|
* SFTP push sync with dry run
|
|
6
|
-
*
|
|
6
|
+
* 1. Upload new files
|
|
7
7
|
* 2. Delete remote files that no longer exist locally
|
|
8
8
|
* 3. Detect changes based on size or modified content and upload them
|
|
9
9
|
*
|
|
@@ -34,6 +34,11 @@ import { createHash } from "crypto";
|
|
|
34
34
|
import { Writable } from "stream";
|
|
35
35
|
import pc from "picocolors";
|
|
36
36
|
|
|
37
|
+
// Colors for the State
|
|
38
|
+
const ADD = pc.green("+"); // Added
|
|
39
|
+
const CHA = pc.yellow("~"); // Changed
|
|
40
|
+
const DEL = pc.red("-"); // deleted
|
|
41
|
+
|
|
37
42
|
// ---------------------------------------------------------------------------
|
|
38
43
|
// CLI arguments
|
|
39
44
|
// ---------------------------------------------------------------------------
|
|
@@ -417,7 +422,7 @@ async function main() {
|
|
|
417
422
|
const start = Date.now();
|
|
418
423
|
|
|
419
424
|
log("\n\n==================================================================");
|
|
420
|
-
log(pc.bold("š
|
|
425
|
+
log(pc.bold("š SFTP Push-Synchronisation: sftp-push-sync"));
|
|
421
426
|
log(` Connection: ${pc.cyan(TARGET)} (Worker: ${CONNECTION.workers})`);
|
|
422
427
|
log(` Host:Port: ${pc.green(CONNECTION.host)}:${pc.green(CONNECTION.port)}`);
|
|
423
428
|
log(` Local: ${pc.green(CONNECTION.localRoot)}`);
|
|
@@ -475,14 +480,14 @@ async function main() {
|
|
|
475
480
|
|
|
476
481
|
if (!r) {
|
|
477
482
|
toAdd.push({ rel, local: l, remotePath });
|
|
478
|
-
log(`${pc.green("
|
|
483
|
+
log(`${ADD} ${pc.green("New:")} ${rel}`);
|
|
479
484
|
continue;
|
|
480
485
|
}
|
|
481
486
|
|
|
482
487
|
// 1. size comparison
|
|
483
488
|
if (l.size !== r.size) {
|
|
484
489
|
toUpdate.push({ rel, local: l, remote: r, remotePath });
|
|
485
|
-
log(`${pc.yellow("
|
|
490
|
+
log(`${CHANGE} ${pc.yellow("Size changed:")} ${rel}`);
|
|
486
491
|
continue;
|
|
487
492
|
}
|
|
488
493
|
|
|
@@ -508,11 +513,11 @@ async function main() {
|
|
|
508
513
|
if (VERBOSE) {
|
|
509
514
|
const diff = diffWords(remoteStr, localStr);
|
|
510
515
|
const blocks = diff.filter((d) => d.added || d.removed).length;
|
|
511
|
-
vlog(`
|
|
516
|
+
vlog(` ${CHANGE} text difference (${blocks} Blocks) in ${rel}`);
|
|
512
517
|
}
|
|
513
518
|
|
|
514
519
|
toUpdate.push({ rel, local: l, remote: r, remotePath });
|
|
515
|
-
log(`${pc.yellow("
|
|
520
|
+
log(`${CHANGE} ${pc.yellow("Content changed(Text):")} ${rel}`);
|
|
516
521
|
} else {
|
|
517
522
|
// Binary: Hash comparison with cache
|
|
518
523
|
const localMeta = l;
|
|
@@ -529,13 +534,13 @@ async function main() {
|
|
|
529
534
|
}
|
|
530
535
|
|
|
531
536
|
if (VERBOSE) {
|
|
532
|
-
vlog(`
|
|
537
|
+
vlog(` ${CHA} Hash different(binary): ${rel}`);
|
|
533
538
|
vlog(` local: ${localHash}`);
|
|
534
539
|
vlog(` remote: ${remoteHash}`);
|
|
535
540
|
}
|
|
536
541
|
|
|
537
542
|
toUpdate.push({ rel, local: l, remote: r, remotePath });
|
|
538
|
-
log(`${pc.yellow("
|
|
543
|
+
log(`${CHANGE} ${pc.yellow("Content changed (Binary):")} ${rel}`);
|
|
539
544
|
}
|
|
540
545
|
}
|
|
541
546
|
|
|
@@ -544,7 +549,7 @@ async function main() {
|
|
|
544
549
|
if (!localKeys.has(rel)) {
|
|
545
550
|
const r = remote.get(rel);
|
|
546
551
|
toDelete.push({ rel, remotePath: r.remotePath });
|
|
547
|
-
log(
|
|
552
|
+
log(` ${DEL} ${pc.red("Remove:")} ${rel}`);
|
|
548
553
|
}
|
|
549
554
|
}
|
|
550
555
|
|
|
@@ -616,21 +621,20 @@ async function main() {
|
|
|
616
621
|
// Summary
|
|
617
622
|
log("\n" + pc.bold(pc.cyan("š Summary:")));
|
|
618
623
|
log(` Dauer: ${pc.green(duration + " s")}`);
|
|
619
|
-
log(`
|
|
620
|
-
log(`
|
|
621
|
-
log(`
|
|
624
|
+
log(` ${ADD} Added : ${toAdd.length}`);
|
|
625
|
+
log(` ${CHA} Changed: ${toUpdate.length}`);
|
|
626
|
+
log(` ${DEL} Deleted: ${toDelete.length}`);
|
|
622
627
|
|
|
623
628
|
if (toAdd.length || toUpdate.length || toDelete.length) {
|
|
624
629
|
log("\nš Changes:");
|
|
625
|
-
[...toAdd.map((t) => t.rel)].sort().forEach((f) => console.log(` ${
|
|
626
|
-
[...toUpdate.map((t) => t.rel)].sort().forEach((f) => console.log(` ${
|
|
627
|
-
[...toDelete.map((t) => t.rel)].sort().forEach((f) => console.log(` ${
|
|
630
|
+
[...toAdd.map((t) => t.rel)].sort().forEach((f) => console.log(` ${ADD} ${f}`));
|
|
631
|
+
[...toUpdate.map((t) => t.rel)].sort().forEach((f) => console.log(` ${CHA} ${f}`));
|
|
632
|
+
[...toDelete.map((t) => t.rel)].sort().forEach((f) => console.log(` ${DEL} ${f}`));
|
|
628
633
|
} else {
|
|
629
634
|
log("\nNo changes.");
|
|
630
635
|
}
|
|
631
636
|
|
|
632
637
|
log("\n" + pc.bold(pc.green("ā
Sync complete.")));
|
|
633
|
-
log("==================================================================\n\n");
|
|
634
638
|
} catch (err) {
|
|
635
639
|
elog(pc.red("ā Synchronisation error:"), err);
|
|
636
640
|
process.exitCode = 1;
|
|
@@ -642,6 +646,7 @@ async function main() {
|
|
|
642
646
|
} finally {
|
|
643
647
|
try {
|
|
644
648
|
await sftp.end();
|
|
649
|
+
log("==================================================================\n\n");
|
|
645
650
|
} catch {
|
|
646
651
|
// ignore
|
|
647
652
|
}
|