@electerm/ssh2 1.18.0 → 1.18.2
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/lib/client.js +2 -2
- package/lib/protocol/SFTP.js +66 -45
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -244,7 +244,7 @@ class Client extends EventEmitter {
|
|
|
244
244
|
? cfg.debug
|
|
245
245
|
: undefined);
|
|
246
246
|
|
|
247
|
-
this.config.
|
|
247
|
+
this.config.encode = cfg.encode || 'utf8';
|
|
248
248
|
|
|
249
249
|
if (cfg.agentForward === true && !this.config.allowAgentFwd) {
|
|
250
250
|
throw new Error(
|
|
@@ -606,7 +606,7 @@ class Client extends EventEmitter {
|
|
|
606
606
|
};
|
|
607
607
|
const instance = (
|
|
608
608
|
isSFTP
|
|
609
|
-
? new SFTP(this, chanInfo, { debug, encoding: this.config.
|
|
609
|
+
? new SFTP(this, chanInfo, { debug, encoding: this.config.encode })
|
|
610
610
|
: new Channel(this, chanInfo)
|
|
611
611
|
);
|
|
612
612
|
this._chanMgr.update(info.recipient, instance);
|
package/lib/protocol/SFTP.js
CHANGED
|
@@ -341,7 +341,8 @@ class SFTP extends EventEmitter {
|
|
|
341
341
|
uint32 pflags
|
|
342
342
|
ATTRS attrs
|
|
343
343
|
*/
|
|
344
|
-
const
|
|
344
|
+
const pathBuf = iconv.encode(path, this._encoding);
|
|
345
|
+
const pathLen = pathBuf.length;
|
|
345
346
|
let p = 9;
|
|
346
347
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen + 4 + 4 + attrsLen);
|
|
347
348
|
|
|
@@ -351,7 +352,7 @@ class SFTP extends EventEmitter {
|
|
|
351
352
|
writeUInt32BE(buf, reqid, 5);
|
|
352
353
|
|
|
353
354
|
writeUInt32BE(buf, pathLen, p);
|
|
354
|
-
buf.
|
|
355
|
+
buf.set(pathBuf, p += 4);
|
|
355
356
|
writeUInt32BE(buf, flags, p += pathLen);
|
|
356
357
|
writeUInt32BE(buf, attrsFlags, p += 4);
|
|
357
358
|
if (attrsLen) {
|
|
@@ -736,7 +737,8 @@ class SFTP extends EventEmitter {
|
|
|
736
737
|
uint32 id
|
|
737
738
|
string filename
|
|
738
739
|
*/
|
|
739
|
-
const
|
|
740
|
+
const fnameBuf = iconv.encode(filename, this._encoding);
|
|
741
|
+
const fnameLen = fnameBuf.length;
|
|
740
742
|
let p = 9;
|
|
741
743
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + fnameLen);
|
|
742
744
|
|
|
@@ -746,7 +748,7 @@ class SFTP extends EventEmitter {
|
|
|
746
748
|
writeUInt32BE(buf, reqid, 5);
|
|
747
749
|
|
|
748
750
|
writeUInt32BE(buf, fnameLen, p);
|
|
749
|
-
buf.
|
|
751
|
+
buf.set(fnameBuf, p += 4);
|
|
750
752
|
|
|
751
753
|
this._requests[reqid] = { cb };
|
|
752
754
|
|
|
@@ -764,8 +766,10 @@ class SFTP extends EventEmitter {
|
|
|
764
766
|
string oldpath
|
|
765
767
|
string newpath
|
|
766
768
|
*/
|
|
767
|
-
const
|
|
768
|
-
const
|
|
769
|
+
const oldBuf = iconv.encode(oldPath, this._encoding);
|
|
770
|
+
const newBuf = iconv.encode(newPath, this._encoding);
|
|
771
|
+
const oldLen = oldBuf.length;
|
|
772
|
+
const newLen = newBuf.length;
|
|
769
773
|
let p = 9;
|
|
770
774
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + oldLen + 4 + newLen);
|
|
771
775
|
|
|
@@ -775,9 +779,9 @@ class SFTP extends EventEmitter {
|
|
|
775
779
|
writeUInt32BE(buf, reqid, 5);
|
|
776
780
|
|
|
777
781
|
writeUInt32BE(buf, oldLen, p);
|
|
778
|
-
buf.
|
|
782
|
+
buf.set(oldBuf, p += 4);
|
|
779
783
|
writeUInt32BE(buf, newLen, p += oldLen);
|
|
780
|
-
buf.
|
|
784
|
+
buf.set(newBuf, p += 4);
|
|
781
785
|
|
|
782
786
|
this._requests[reqid] = { cb };
|
|
783
787
|
|
|
@@ -808,7 +812,8 @@ class SFTP extends EventEmitter {
|
|
|
808
812
|
string path
|
|
809
813
|
ATTRS attrs
|
|
810
814
|
*/
|
|
811
|
-
const
|
|
815
|
+
const pathBuf = iconv.encode(path, this._encoding);
|
|
816
|
+
const pathLen = pathBuf.length;
|
|
812
817
|
let p = 9;
|
|
813
818
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen + 4 + attrsLen);
|
|
814
819
|
|
|
@@ -818,7 +823,7 @@ class SFTP extends EventEmitter {
|
|
|
818
823
|
writeUInt32BE(buf, reqid, 5);
|
|
819
824
|
|
|
820
825
|
writeUInt32BE(buf, pathLen, p);
|
|
821
|
-
buf.
|
|
826
|
+
buf.set(pathBuf, p += 4);
|
|
822
827
|
writeUInt32BE(buf, flags, p += pathLen);
|
|
823
828
|
if (attrsLen) {
|
|
824
829
|
p += 4;
|
|
@@ -846,7 +851,8 @@ class SFTP extends EventEmitter {
|
|
|
846
851
|
uint32 id
|
|
847
852
|
string path
|
|
848
853
|
*/
|
|
849
|
-
const
|
|
854
|
+
const pathBuf = iconv.encode(path, this._encoding);
|
|
855
|
+
const pathLen = pathBuf.length;
|
|
850
856
|
let p = 9;
|
|
851
857
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen);
|
|
852
858
|
|
|
@@ -856,7 +862,7 @@ class SFTP extends EventEmitter {
|
|
|
856
862
|
writeUInt32BE(buf, reqid, 5);
|
|
857
863
|
|
|
858
864
|
writeUInt32BE(buf, pathLen, p);
|
|
859
|
-
buf.
|
|
865
|
+
buf.set(pathBuf, p += 4);
|
|
860
866
|
|
|
861
867
|
this._requests[reqid] = { cb };
|
|
862
868
|
|
|
@@ -989,7 +995,8 @@ class SFTP extends EventEmitter {
|
|
|
989
995
|
uint32 id
|
|
990
996
|
string path
|
|
991
997
|
*/
|
|
992
|
-
const
|
|
998
|
+
const pathBuf = iconv.encode(path, this._encoding);
|
|
999
|
+
const pathLen = pathBuf.length;
|
|
993
1000
|
let p = 9;
|
|
994
1001
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen);
|
|
995
1002
|
|
|
@@ -999,7 +1006,7 @@ class SFTP extends EventEmitter {
|
|
|
999
1006
|
writeUInt32BE(buf, reqid, 5);
|
|
1000
1007
|
|
|
1001
1008
|
writeUInt32BE(buf, pathLen, p);
|
|
1002
|
-
buf.
|
|
1009
|
+
buf.set(pathBuf, p += 4);
|
|
1003
1010
|
|
|
1004
1011
|
this._requests[reqid] = { cb };
|
|
1005
1012
|
|
|
@@ -1016,7 +1023,8 @@ class SFTP extends EventEmitter {
|
|
|
1016
1023
|
uint32 id
|
|
1017
1024
|
string path
|
|
1018
1025
|
*/
|
|
1019
|
-
const
|
|
1026
|
+
const pathBuf = iconv.encode(path, this._encoding);
|
|
1027
|
+
const pathLen = pathBuf.length;
|
|
1020
1028
|
let p = 9;
|
|
1021
1029
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen);
|
|
1022
1030
|
|
|
@@ -1026,7 +1034,7 @@ class SFTP extends EventEmitter {
|
|
|
1026
1034
|
writeUInt32BE(buf, reqid, 5);
|
|
1027
1035
|
|
|
1028
1036
|
writeUInt32BE(buf, pathLen, p);
|
|
1029
|
-
buf.
|
|
1037
|
+
buf.set(pathBuf, p += 4);
|
|
1030
1038
|
|
|
1031
1039
|
this._requests[reqid] = { cb };
|
|
1032
1040
|
|
|
@@ -1043,7 +1051,8 @@ class SFTP extends EventEmitter {
|
|
|
1043
1051
|
uint32 id
|
|
1044
1052
|
string path
|
|
1045
1053
|
*/
|
|
1046
|
-
const
|
|
1054
|
+
const pathBuf = iconv.encode(path, this._encoding);
|
|
1055
|
+
const pathLen = pathBuf.length;
|
|
1047
1056
|
let p = 9;
|
|
1048
1057
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen);
|
|
1049
1058
|
|
|
@@ -1053,7 +1062,7 @@ class SFTP extends EventEmitter {
|
|
|
1053
1062
|
writeUInt32BE(buf, reqid, 5);
|
|
1054
1063
|
|
|
1055
1064
|
writeUInt32BE(buf, pathLen, p);
|
|
1056
|
-
buf.
|
|
1065
|
+
buf.set(pathBuf, p += 4);
|
|
1057
1066
|
|
|
1058
1067
|
this._requests[reqid] = { cb };
|
|
1059
1068
|
|
|
@@ -1082,7 +1091,8 @@ class SFTP extends EventEmitter {
|
|
|
1082
1091
|
string path
|
|
1083
1092
|
ATTRS attrs
|
|
1084
1093
|
*/
|
|
1085
|
-
const
|
|
1094
|
+
const pathBuf = iconv.encode(path, this._encoding);
|
|
1095
|
+
const pathLen = pathBuf.length;
|
|
1086
1096
|
let p = 9;
|
|
1087
1097
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen + 4 + attrsLen);
|
|
1088
1098
|
|
|
@@ -1092,7 +1102,7 @@ class SFTP extends EventEmitter {
|
|
|
1092
1102
|
writeUInt32BE(buf, reqid, 5);
|
|
1093
1103
|
|
|
1094
1104
|
writeUInt32BE(buf, pathLen, p);
|
|
1095
|
-
buf.
|
|
1105
|
+
buf.set(pathBuf, p += 4);
|
|
1096
1106
|
writeUInt32BE(buf, flags, p += pathLen);
|
|
1097
1107
|
if (attrsLen) {
|
|
1098
1108
|
p += 4;
|
|
@@ -1207,7 +1217,8 @@ class SFTP extends EventEmitter {
|
|
|
1207
1217
|
uint32 id
|
|
1208
1218
|
string path
|
|
1209
1219
|
*/
|
|
1210
|
-
const
|
|
1220
|
+
const pathBuf = iconv.encode(path, this._encoding);
|
|
1221
|
+
const pathLen = pathBuf.length;
|
|
1211
1222
|
let p = 9;
|
|
1212
1223
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen);
|
|
1213
1224
|
|
|
@@ -1217,7 +1228,7 @@ class SFTP extends EventEmitter {
|
|
|
1217
1228
|
writeUInt32BE(buf, reqid, 5);
|
|
1218
1229
|
|
|
1219
1230
|
writeUInt32BE(buf, pathLen, p);
|
|
1220
|
-
buf.
|
|
1231
|
+
buf.set(pathBuf, p += 4);
|
|
1221
1232
|
|
|
1222
1233
|
this._requests[reqid] = {
|
|
1223
1234
|
cb: (err, names) => {
|
|
@@ -1245,8 +1256,10 @@ class SFTP extends EventEmitter {
|
|
|
1245
1256
|
string linkpath
|
|
1246
1257
|
string targetpath
|
|
1247
1258
|
*/
|
|
1248
|
-
const
|
|
1249
|
-
const
|
|
1259
|
+
const linkBuf = iconv.encode(linkPath, this._encoding);
|
|
1260
|
+
const targetBuf = iconv.encode(targetPath, this._encoding);
|
|
1261
|
+
const linkLen = linkBuf.length;
|
|
1262
|
+
const targetLen = targetBuf.length;
|
|
1250
1263
|
let p = 9;
|
|
1251
1264
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + linkLen + 4 + targetLen);
|
|
1252
1265
|
|
|
@@ -1258,14 +1271,14 @@ class SFTP extends EventEmitter {
|
|
|
1258
1271
|
if (this._isOpenSSH) {
|
|
1259
1272
|
// OpenSSH has linkpath and targetpath positions switched
|
|
1260
1273
|
writeUInt32BE(buf, targetLen, p);
|
|
1261
|
-
buf.
|
|
1274
|
+
buf.set(targetBuf, p += 4);
|
|
1262
1275
|
writeUInt32BE(buf, linkLen, p += targetLen);
|
|
1263
|
-
buf.
|
|
1276
|
+
buf.set(linkBuf, p += 4);
|
|
1264
1277
|
} else {
|
|
1265
1278
|
writeUInt32BE(buf, linkLen, p);
|
|
1266
|
-
buf.
|
|
1279
|
+
buf.set(linkBuf, p += 4);
|
|
1267
1280
|
writeUInt32BE(buf, targetLen, p += linkLen);
|
|
1268
|
-
buf.
|
|
1281
|
+
buf.set(targetBuf, p += 4);
|
|
1269
1282
|
}
|
|
1270
1283
|
|
|
1271
1284
|
this._requests[reqid] = { cb };
|
|
@@ -1283,7 +1296,8 @@ class SFTP extends EventEmitter {
|
|
|
1283
1296
|
uint32 id
|
|
1284
1297
|
string path
|
|
1285
1298
|
*/
|
|
1286
|
-
const
|
|
1299
|
+
const pathBuf = iconv.encode(path, this._encoding);
|
|
1300
|
+
const pathLen = pathBuf.length;
|
|
1287
1301
|
let p = 9;
|
|
1288
1302
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen);
|
|
1289
1303
|
|
|
@@ -1293,7 +1307,7 @@ class SFTP extends EventEmitter {
|
|
|
1293
1307
|
writeUInt32BE(buf, reqid, 5);
|
|
1294
1308
|
|
|
1295
1309
|
writeUInt32BE(buf, pathLen, p);
|
|
1296
|
-
buf.
|
|
1310
|
+
buf.set(pathBuf, p += 4);
|
|
1297
1311
|
|
|
1298
1312
|
this._requests[reqid] = {
|
|
1299
1313
|
cb: (err, names) => {
|
|
@@ -1327,8 +1341,10 @@ class SFTP extends EventEmitter {
|
|
|
1327
1341
|
string oldpath
|
|
1328
1342
|
string newpath
|
|
1329
1343
|
*/
|
|
1330
|
-
const
|
|
1331
|
-
const
|
|
1344
|
+
const oldBuf = iconv.encode(oldPath, this._encoding);
|
|
1345
|
+
const newBuf = iconv.encode(newPath, this._encoding);
|
|
1346
|
+
const oldLen = oldBuf.length;
|
|
1347
|
+
const newLen = newBuf.length;
|
|
1332
1348
|
let p = 9;
|
|
1333
1349
|
const buf =
|
|
1334
1350
|
Buffer.allocUnsafe(4 + 1 + 4 + 4 + 24 + 4 + oldLen + 4 + newLen);
|
|
@@ -1341,9 +1357,9 @@ class SFTP extends EventEmitter {
|
|
|
1341
1357
|
writeUInt32BE(buf, 24, p);
|
|
1342
1358
|
buf.utf8Write('posix-rename@openssh.com', p += 4, 24);
|
|
1343
1359
|
writeUInt32BE(buf, oldLen, p += 24);
|
|
1344
|
-
buf.
|
|
1360
|
+
buf.set(oldBuf, p += 4);
|
|
1345
1361
|
writeUInt32BE(buf, newLen, p += oldLen);
|
|
1346
|
-
buf.
|
|
1362
|
+
buf.set(newBuf, p += 4);
|
|
1347
1363
|
|
|
1348
1364
|
this._requests[reqid] = { cb };
|
|
1349
1365
|
|
|
@@ -1366,7 +1382,8 @@ class SFTP extends EventEmitter {
|
|
|
1366
1382
|
string "statvfs@openssh.com"
|
|
1367
1383
|
string path
|
|
1368
1384
|
*/
|
|
1369
|
-
const
|
|
1385
|
+
const pathBuf = iconv.encode(path, this._encoding);
|
|
1386
|
+
const pathLen = pathBuf.length;
|
|
1370
1387
|
let p = 9;
|
|
1371
1388
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + 19 + 4 + pathLen);
|
|
1372
1389
|
|
|
@@ -1378,7 +1395,7 @@ class SFTP extends EventEmitter {
|
|
|
1378
1395
|
writeUInt32BE(buf, 19, p);
|
|
1379
1396
|
buf.utf8Write('statvfs@openssh.com', p += 4, 19);
|
|
1380
1397
|
writeUInt32BE(buf, pathLen, p += 19);
|
|
1381
|
-
buf.
|
|
1398
|
+
buf.set(pathBuf, p += 4);
|
|
1382
1399
|
|
|
1383
1400
|
this._requests[reqid] = { extended: 'statvfs@openssh.com', cb };
|
|
1384
1401
|
|
|
@@ -1439,8 +1456,10 @@ class SFTP extends EventEmitter {
|
|
|
1439
1456
|
string oldpath
|
|
1440
1457
|
string newpath
|
|
1441
1458
|
*/
|
|
1442
|
-
const
|
|
1443
|
-
const
|
|
1459
|
+
const oldBuf = iconv.encode(oldPath, this._encoding);
|
|
1460
|
+
const newBuf = iconv.encode(newPath, this._encoding);
|
|
1461
|
+
const oldLen = oldBuf.length;
|
|
1462
|
+
const newLen = newBuf.length;
|
|
1444
1463
|
let p = 9;
|
|
1445
1464
|
const buf =
|
|
1446
1465
|
Buffer.allocUnsafe(4 + 1 + 4 + 4 + 20 + 4 + oldLen + 4 + newLen);
|
|
@@ -1453,9 +1472,9 @@ class SFTP extends EventEmitter {
|
|
|
1453
1472
|
writeUInt32BE(buf, 20, p);
|
|
1454
1473
|
buf.utf8Write('hardlink@openssh.com', p += 4, 20);
|
|
1455
1474
|
writeUInt32BE(buf, oldLen, p += 20);
|
|
1456
|
-
buf.
|
|
1475
|
+
buf.set(oldBuf, p += 4);
|
|
1457
1476
|
writeUInt32BE(buf, newLen, p += oldLen);
|
|
1458
|
-
buf.
|
|
1477
|
+
buf.set(newBuf, p += 4);
|
|
1459
1478
|
|
|
1460
1479
|
this._requests[reqid] = { cb };
|
|
1461
1480
|
|
|
@@ -1526,7 +1545,8 @@ class SFTP extends EventEmitter {
|
|
|
1526
1545
|
string path
|
|
1527
1546
|
ATTRS attrs
|
|
1528
1547
|
*/
|
|
1529
|
-
const
|
|
1548
|
+
const pathBuf = iconv.encode(path, this._encoding);
|
|
1549
|
+
const pathLen = pathBuf.length;
|
|
1530
1550
|
let p = 9;
|
|
1531
1551
|
const buf =
|
|
1532
1552
|
Buffer.allocUnsafe(4 + 1 + 4 + 4 + 20 + 4 + pathLen + 4 + attrsLen);
|
|
@@ -1540,7 +1560,7 @@ class SFTP extends EventEmitter {
|
|
|
1540
1560
|
buf.utf8Write('lsetstat@openssh.com', p += 4, 20);
|
|
1541
1561
|
|
|
1542
1562
|
writeUInt32BE(buf, pathLen, p += 20);
|
|
1543
|
-
buf.
|
|
1563
|
+
buf.set(pathBuf, p += 4);
|
|
1544
1564
|
|
|
1545
1565
|
writeUInt32BE(buf, flags, p += pathLen);
|
|
1546
1566
|
if (attrsLen) {
|
|
@@ -1575,7 +1595,8 @@ class SFTP extends EventEmitter {
|
|
|
1575
1595
|
string "expand-path@openssh.com"
|
|
1576
1596
|
string path
|
|
1577
1597
|
*/
|
|
1578
|
-
const
|
|
1598
|
+
const pathBuf = iconv.encode(path, this._encoding);
|
|
1599
|
+
const pathLen = pathBuf.length;
|
|
1579
1600
|
let p = 9;
|
|
1580
1601
|
const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + 23 + 4 + pathLen);
|
|
1581
1602
|
|
|
@@ -1587,8 +1608,8 @@ class SFTP extends EventEmitter {
|
|
|
1587
1608
|
writeUInt32BE(buf, 23, p);
|
|
1588
1609
|
buf.utf8Write('expand-path@openssh.com', p += 4, 23);
|
|
1589
1610
|
|
|
1590
|
-
writeUInt32BE(buf, pathLen, p +=
|
|
1591
|
-
buf.
|
|
1611
|
+
writeUInt32BE(buf, pathLen, p += 23);
|
|
1612
|
+
buf.set(pathBuf, p += 4);
|
|
1592
1613
|
|
|
1593
1614
|
this._requests[reqid] = {
|
|
1594
1615
|
cb: (err, names) => {
|
package/package.json
CHANGED