🚧 WIP: sftp manage

This commit is contained in:
萌萌哒赫萝
2023-08-19 21:06:28 -07:00
parent 1629dcaef0
commit e89b3ca6d1
7 changed files with 493 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
import { NodeSSH, Config } from 'node-ssh-no-cpu-features'
import { NodeSSH, Config, SSHExecCommandResponse } from 'node-ssh-no-cpu-features'
import { ISftpPlistConfig } from 'piclist/dist/types'
class SSHClient {
@@ -55,6 +55,31 @@ class SSHClient {
return execResult.code === 0
}
async execCommand (script: string): Promise<SSHExecCommandResponse> {
const execResult = await SSHClient.client.execCommand(script)
return execResult || { code: 1, stdout: '', stderr: '' }
}
async getFile (local: string, remote: string): Promise<boolean> {
if (!this._isConnected) {
throw new Error('SSH 未连接')
}
try {
remote = this.changeWinStylePathToUnix(remote)
local = this.changeWinStylePathToUnix(local)
console.log(`remote: ${remote}, local: ${local}`)
await SSHClient.client.getFile(local, remote)
return true
} catch (err: any) {
console.log(err)
return false
}
}
get isConnected (): boolean {
return SSHClient.client.isConnected()
}
public close (): void {
SSHClient.client.dispose()
this._isConnected = false