(serverId: string)
| 108 | }; |
| 109 | |
| 110 | const getSFTPConnection = async (serverId: string): Promise<SFTPWrapper> => { |
| 111 | const server = await findServerById(serverId); |
| 112 | if (!server.sshKeyId) throw new Error("No SSH key available for this server"); |
| 113 | |
| 114 | return new Promise((resolve, reject) => { |
| 115 | const conn = new Client(); |
| 116 | conn |
| 117 | .on("ready", () => { |
| 118 | conn.sftp((err, sftp) => { |
| 119 | if (err) return reject(err); |
| 120 | resolve(sftp); |
| 121 | }); |
| 122 | }) |
| 123 | .connect({ |
| 124 | host: server.ipAddress, |
| 125 | port: server.port, |
| 126 | username: server.username, |
| 127 | privateKey: server.sshKey?.privateKey, |
| 128 | }); |
| 129 | }); |
| 130 | }; |
| 131 | |
| 132 | const uploadFileToServer = ( |
| 133 | sftp: SFTPWrapper, |
no test coverage detected