i'm trying to configure sftp server in nest.js using this node package ssh2-sftp-client.but i'm getting a error ssh2_sftp_client_1.SftpClient is not a constructor. this is what i have done so far
this is my service file
import { Inject, Injectable } from '@nestjs/common';
import { SftpClient, ConnectConfig, FileInfo } from 'ssh2-sftp-client';
export class ServerService {
private sftp: SftpClient;
constructor() {
this.sftp = new SftpClient();
}
async connect(config: ConnectConfig): Promise<any> {
await this.sftp.connect(config);
return 'server connected';
}
this is my controller file
import { Controller, Inject } from '@nestjs/common';
import { ServerService } from './server.service';
@Controller('server')
export class ServerController {
constructor(
@Inject(ServerService) private readonly sftpService: ServerService,
) {}
async connect() {
try {
await this.sftpService.connect({
host: 'something',
port: portnumber,
username: 'username',
password: 'password',
});
} catch (e) {}
}
anyone here who has configured this package in nest before. any help would be appreciated
Here is my working solution
// any random string for identification
define the config for sftp connection
//declare Client object
Here is an example of listeners.
// finally connect with client