Open alanhe421 opened 2 years ago
list(data.path, /^[^.]/)
返回为字节数,可以自行处理显示为表意的KB,MB之类单位
d
是文件夹-
是文件l
是软链接{
"type": "-",
"name": "admin4.key",
"size": 1679,
"modifyTime": 1651807713000,
"accessTime": 1651807715000,
"rights": { "user": "rw", "group": "r", "other": "r" },
"owner": 0,
"group": 0
}
owner,group字段返回值为ID
下载进度通过step函数可以获取,上传类似
this.sftpClient.fastGet(filePath, localPath, {
concurrency: 64, // integer. Number of concurrent reads to use
chunkSize: 32768, // integer. Size of each read in bytes
step: function (total_transferred, chunk, total) {
console.log('download step', total_transferred, chunk, total, 'percent:', (total_transferred / total * 100).toFixed(0), '%');
}
})
注意,浏览器端JS可以实现多文件转ZIP包,但不支持在用户桌面创建文件夹。
this.sftpClient.connect(this.config).catch(err => {
console.log(`Error: ${err.message}`); // error message will include 'example-client'
});
上传下载文件可以限制下速度
https://github.com/theophilusx/ssh2-sftp-client/issues/259
put方法仅支持上传文件,针对文件夹会报错,需要使用对应API uploadDir
同时空文件支持上传
在下载或者上传大文件时,由于时间消耗太大,用户存在取消的需求
手动断开连接,再重新建立连接。
let stats = {
mode: 33279, // integer representing type and permissions
uid: 1000, // user ID
gid: 985, // group ID
size: 5, // file size
accessTime: 1566868566000, // Last access time. milliseconds
modifyTime: 1566868566000, // last modify time. milliseconds
isDirectory: false, // true if object is a directory
isFile: true, // true if object is a file
isBlockDevice: false, // true if object is a block device
isCharacterDevice: false, // true if object is a character device
isSymbolicLink: false, // true if object is a symbolic link
isFIFO: false, // true if object is a FIFO
isSocket: false // true if object is a socket
};
(rslt.mode& parseInt('777', 8)).toString(8)
https://www.martin-brennan.com/nodejs-file-permissions-fstat/
const RIGHTS_NUM_TO_STR = {
7: 'rwx',
6: 'rw-',
5: 'r-x',
4: 'r--',
3: '-wx',
2: '-w-',
1: '--x',
0: '---',
};
/**
* 例如:16832=>700
*/
function handleFileModeRights(str) {
return (str & parseInt('777', 8)).toString(8)
.split('')
.reduce((res, item) => {
res += RIGHTS_NUM_TO_STR[+item];
return res;
}, '');
}
function handleShortRights(str) {
const processRights = item => item.replace(/-/g, '');
return str.match(/[a-z-]{3}/g)
.reduce((res, item, index) => {
if (index === 0) {
res.user = processRights(item);
}
if (index === 1) {
res.group = processRights(item);
}
if (index === 2) {
res.other = processRights(item);
}
return res;
}, {});
}
function handleLongRights(str) {
return handleShortRights(str.substring(1));
}
list返回文件项,具体参数如下