Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
connect(connection) {
const self = this;
self.emit('debug', 'ftp:connect');
self.client = new ftpClient.Client();
// force PASV mode
self.client.prepareTransfer = ftpClient.enterPassiveModeIPv4;
// logging
self.client.ftp.verbose = true;
self.client.ftp.log = (message) => {
if (message.startsWith('<') || message.startsWith('>')) {
self.emit('log', message.replace(/\'+/g, "").replace(/\\r|\\n/g, " "));
} else {
self.emit('debug', 'ftp:debug: ' + message);
}
};
// options
let options = {
public async connect(config: IConfig): Promise {
if (this.connected) {
await this.disconnect();
}
this.config = config;
this.connected = false;
if (this.isSftp) {
this._sftpClient = new SftpClient();
await this._sftpClient.connect(config);
} else {
this._ftpClient = new FtpClient();
const ftps = config.protocol === 'ftps';
await this._ftpClient.access({
secure: ftps,
secureOptions: ftps ? null : {
rejectUnauthorized: false,
},
...config
});
}
this.connected = true;
this.emit('connect');
}
let { username, password, hostname, port, pathname } = new URL(url);
/*
let client = clientMap[key]
if (client && client.closed == false) {
if (pathname) {
if (cd) {
pathname = pathname.replace(/\/[^\/]+?$/, '')
}
console.log('cd1')
await client.cd(pathname);
}
return client
}
*/
let client = new ftp.Client();
let flag = false
client.ftp.verbose = true
try {
let p = await client.access({
host: hostname,
user: decodeURIComponent(username),
password: decodeURIComponent(password),
port: port || 21,
secure: false
})
if (pathname) {
if (cd) {
pathname = pathname.replace(/\/[^\/]+?$/, '')
}
await client.cd(pathname);
}
async function getFtpClient(options: FtpOptions): Promise {
const ftpClient = new ftp.Client();
ftpClient.ftp.log = tl.debug;
const accessOptions = getAccessOption(options);
const response = await ftpClient.access(accessOptions);
tl.debug("ftp client greeting");
console.log(tl.loc("FTPConnected", response.message));
ftpClient.trackProgress(info => {
console.log(
`File: ${info.name} Type: ${info.type} Transferred: ${info.bytes}`
);
});
return ftpClient;
}
async handleFTP(){
const client = new ftp.Client();
client.ftp.verbose = false;
let refresh = 10;
try {
await client.access({
host: this.ftpConfig.host,
user: this.ftpConfig.username,
password: this.ftpConfig.password,
secure: this.ftpConfig.secure
});
await client.cd(this.ftpConfig.absolutePath);