Skip to content

Commit

Permalink
Add SFTP/SSH importer
Browse files Browse the repository at this point in the history
  • Loading branch information
robinp7720 committed Jan 23, 2024
1 parent 4786e5b commit b08a647
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/seedbox/Seedbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SeedboxImportFTP from './SeedboxImportDrivers/SeedboxImportFTP';
import WarnExtendableError from '../errors/WarnExtendableError';
import logger from '../../submodules/logger';
import SeedboxImportFTPS from './SeedboxImportDrivers/SeedboxImportFTPS';
import SeedboxImportSSH from './SeedboxImportDrivers/SeedboxImportSSH';

export default class Seedbox {
constructor(seedboxConfig) {
Expand All @@ -21,6 +22,10 @@ export default class Seedbox {
case 'ftps':
this.storageDriver = new SeedboxImportFTPS(seedboxStorageDriverOptions);
return;
case'sftp':
case 'ssh':
this.storageDriver = new SeedboxImportSSH(seedboxStorageDriverOptions);
return;
}

return new WarnExtendableError('Invalid seedbox storage driver');
Expand Down
60 changes: 60 additions & 0 deletions src/lib/seedbox/SeedboxImportDrivers/SeedboxImportSSH.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import SeedboxImportDriver from '../SeedboxImportDriver';
import logger from '../../../submodules/logger';
import fs from 'fs';

import Client from 'ssh2-sftp-client';

export default class SeedboxImportSSH extends SeedboxImportDriver {
constructor(config) {
super(config);

this.client = new Client();
}

async setup() {
try {

console.log(this.config);

await this.client.connect({
host: this.config.host,
port: this.config.port || 22,
user: this.config.username,
password: this.config.password,
});

} catch (e) {
logger.log('INFO', e);
}
}

async list(path) {
const listing = await this.client.list(path);

return listing.map(item => {
return {
name: item.name,
type: item.type === 'd'? 1:0
};
});
}

async copy(origin, destination) {
const client = new Client();

await client.connect({
host: this.config.host,
port: this.config.port || 22,
user: this.config.username,
password: this.config.password,
});

await client.fastGet(origin, destination, {
step: (transfered, chunk, total) => {
// console.log(transfered, chunk, total, transfered/total);
}
});

await client.end();
}
}

0 comments on commit b08a647

Please sign in to comment.