| 398 | } |
| 399 | |
| 400 | async connect() { |
| 401 | await new Promise((resolve, reject) => { |
| 402 | const retry = (err) => { |
| 403 | if (settings.value.retryRemoteFsAfterFail) { |
| 404 | if (++this.#retry > this.#MAX_TRY) { |
| 405 | this.#retry = 0; |
| 406 | reject(err); |
| 407 | } else { |
| 408 | this.connect().then(resolve).catch(reject); |
| 409 | } |
| 410 | } else { |
| 411 | reject(err); |
| 412 | } |
| 413 | }; |
| 414 | |
| 415 | if (this.#authenticationType === "key") { |
| 416 | sftp.connectUsingKeyFile( |
| 417 | this.#hostname, |
| 418 | this.#port, |
| 419 | this.#username, |
| 420 | this.#keyFile, |
| 421 | this.#passPhrase, |
| 422 | resolve, |
| 423 | retry, |
| 424 | ); |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | sftp.connectUsingPassword( |
| 429 | this.#hostname, |
| 430 | this.#port, |
| 431 | this.#username, |
| 432 | this.#password, |
| 433 | resolve, |
| 434 | retry, |
| 435 | ); |
| 436 | }); |
| 437 | } |
| 438 | |
| 439 | async exists() { |
| 440 | return (await this.stat()).exists; |