Node.js - FTP through HTTP Tunnel (FTP over HTTP Proxy) - node.js

I am looking for an opportunity to connect FTP-Server via HTTP-Proxy-Server. I tried different npm packages (jsftp, ftp etc.), but the connection does not work. I have tried a few SOCKS packages but they seem outdated. Here is an example from the package jsftp. Unfortunately, the example does not work and I can not find any solution
const {SocksClient} = require('socks');
const ftp = new Ffp({
host: 'localhost',
port: 3333,
user: 'user',
pass: 'password',
createSocket: ({port, host}, firstAction) => {
return SocksClient.createConnection({
proxy: {
ipaddress: '159.203.75.200'
port: 1080,
type: 5
},
command: 'connect',
destination: {
host,
port
}
})
}
})

This solution worked for me. However, it uses platform-dependent packages and is only commercially available starting from USD 289.
This solution looked promising, but I couldn't get it to work properly. It created files I wanted to copy, but they always ended up being empty.

Related

AdonisJS 5, dynamically connect database

Hi used Adonis Js 5 with the new version. I have multiple database clients with the same database structure, can I create a new database connection without declaring the config at config/database.ts? it means I can create a connection on the fly.
Yes finally I can make it, with this:
Database.manager.patch(this.database.name, {
client: 'mysql',
connection: {
host: Env.get('DB_HOST'),
port: Env.get('DB_PORT'),
user: this.database.username,
password: this.database.password,
database: this.database.name,
},
debug: Env.get('DB_DEBUG', false),
})
Database.manager.connect(this.database.name)

connect ECONNREFUSED 127.0.0.1:587 (nodemailer + mailtrap)

I've been trying to get the basic combination of nodemailer, using a mailtrap.io account to work, and striking out.
Here is my app.js:
const nodemailer = require('nodemailer');
let transport = nodemailer.createTransport({
host: "smtp.mailtrap.io",
port: 2525,
// secure: true,
auth: {
user: "myusername",
pass: "mypassword"
},
debug: true,
logger: true
});
let scrapeEmailMessage = {
//from: 'myemail#gmail.com',
to: 'myemail#gmail.com',
subject: 'Hello World',
text: 'hello world'
};
let mailTransporter = nodemailer.createTransport(transport);
mailTransporter.sendMail(scrapeEmailMessage, function(err, data) {
if(err) {
console.log(err);
} else {
console.log('Email sent successfully');
}
});
And here is the error output I'm getting:
[2020-11-10 14:32:20] DEBUG Creating transport: nodemailer (6.4.15; +https://nodemailer.com/; SMTP/6.4.15[client:6.4.15])
[2020-11-10 14:32:20] DEBUG Creating transport: nodemailer (6.4.15; +https://nodemailer.com/; SMTP/6.4.15[client:6.4.15])
[2020-11-10 14:32:20] DEBUG Sending mail using SMTP/6.4.15[client:6.4.15]
[2020-11-10 14:32:20] DEBUG [YlvPyvxQxE] Resolved localhost as 127.0.0.1 [cache miss]
[2020-11-10 14:32:22] ERROR [YlvPyvxQxE] connect ECONNREFUSED 127.0.0.1:587
[2020-11-10 14:32:22] DEBUG [YlvPyvxQxE] Closing connection to the server using "destroy"
[2020-11-10 14:32:22] ERROR Send Error: connect ECONNREFUSED 127.0.0.1:587
Error: connect ECONNREFUSED 127.0.0.1:587
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1129:14) {
errno: 'ECONNREFUSED',
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 587,
command: 'CONN'
}
I've tried a number of things to fix it, and continually get this same error message:
Turning on the "less secure apps" options in Gmail and using the above code to try to connect to smtp.gmail.com instead.
Manually editing the port numbers in the code above.
Toggling secure mode on and off in the code above.
Adding Windows Defender Firewall exceptions on ports 587, 465, as well as a couple others just for fun to see if they would work.
Disabling Windows Defender Firewall completely.
Running the code on other computers on my home network.
Checking "netstat -an" to see if ports 587 or 465 are listed. They are not, but is this port open all the time or only opened when needed? Could this be the issue?
Anyone have any ideas on what might be going on here? I'm just a normal guy using his home internet connection to write a small program to send himself an email alert once a day. Could my ISP be blocking this or something?
EDIT- Adding a couple new things I've tried that haven't worked:
Transport option "ignoreTLS: true/false" (tried both)
Transport option "requireTLS: true/false" (tried both)
You are creating two transporter.
Instead of this :
let mailTransporter = nodemailer.createTransport(transport);
and
mailTransporter.sendMail()
Do this :
transport.sendMail()
modify;
let transport = nodemailer.createTransport({
to be;
let transport = {
and remove the closing parentheses; }); to be };
I got this error, and it's because I was using port 25 instead of port 2525. It says 25 is an option but seems to not work for me.

Include Amazon RDS endpoint in Node JS error: An identifier or keyword cannot immediately follow a numeric literal

I was trying to connect my Node JS application with Amazon RDS following this tutorial Adding Node JS to RDS application, in my case I have the following:
const pool = mysql.createPool({
connectionLimit: 10,
host: process.env.factsDB.abcdefg.eu-west-2.rds.amazonaws.com,
user: process.env.johnDoe,
password: process.env.password123,
port: process.env.3306,
database: 'factsDB',
debug: false
});
However it gave me the following error:
An identifier or keyword cannot immediately follow a numeric literal
at rds at the host, and another error
',' expected
at env.3306 at port, any idea how to fix these?
The process.env in the link provided is used to read environmental variables. However, from what I understand, you provide your db details directly into createPool.
Thus you can try the following:
const pool = mysql.createPool({
connectionLimit: 10,
host: "factsDB.abcdefg.eu-west-2.rds.amazonaws.com",
user: "johnDoe",
password: "password123",
port: 3306,
database: 'factsDB',
debug: false
});

SSL certificates with RedBird.js and Node.js with two domains on one server

Bad(?) news "SSL For Free is joining ZeroSSL". Since their news I renewed my certificates and TLS stopped working. Used to work fine.
I believe free certs are now from something called AutoSSL. Hopefully.
With new certificates I get error "You may need to install an Intermediate/chain certificate to link it to a trusted root certificate" from https://www.sslshopper.com/ssl-checker.html and this error "TLS Certificate is not trusted" from https://www.digicert.com/help.
Browsers are smart enough to mask the problem but my Android app uses an API and it stopped working.
Anyone else getting TLS problems since ZeroSSL got involved?
I'm using redbirdjs on nodejs which is awesome since its so simple (two domains, same server), but Zero provides no installation instructions for my setup. (My domains are small in traffic so using the fastest webservers etc. isn't an issue).
Zero took away the 2 domains in one cert option (gee thanks) so my updated script looks like:
const { constants } = require('crypto');
var redbird = new require('redbird')({ port: 8080, ssl: { port: 443 }});
redbird.register('domain1.com', 'http://127.0.0.1:9443', {
ssl: {
key: 'ssl/domain1/private.key',
cert: 'ssl/domain1/certificate.crt',
ca: 'ssl/domain1/ca_bundle.crt',
secureOptions: constants.SSL_OP_NO_TLSv1 | constants.SSL_OP_NO_TLSv1_1,
}
});
redbird.register('domain2.com', 'http://127.0.0.1:3003', {
ssl: {
key: 'ssl/domain2/private.key',
cert: 'ssl/domain2/certificate.crt',
ca: 'ssl/domain2/ca_bundle.crt',
secureOptions: constants.SSL_OP_NO_TLSv1 | constants.SSL_OP_NO_TLSv1_1,
}
});
Other than separating the domain ssl config, it is the same as what used to work with SSLForFree.
I read somewhere that "free" SSL CA's do not necessarily provide the "full chain".
Anyone know how to get TLS working again with ZeroSSL on redbirdjs and nodejs?
Well, I got it working. I used https://whatsmychaincert.com, which I think just literally joins a couple files together. Either way for redbird fans (like me) here is the script for multiple domains on the same server.
// https://github.com/OptimalBits/redbird
// https://whatsmychaincert.com/
// 9443 is where domain1 server runs locally
// 3003 is where domain2 server runs locally
const { constants } = require('crypto');
var redbird = new require('redbird')({ port: 8080, ssl: { port: 443 }});
redbird.register('domain1.com', 'http://127.0.0.1:9443', {
ssl: {
port: 9443,
key: 'ssl/domain1/private.key',
cert: 'ssl/domain1/domain1.chained.crt', // used whatsmychaincert.com to generate ('enter hostname', no need to include root)
secureOptions: constants.SSL_OP_NO_TLSv1 | constants.SSL_OP_NO_TLSv1_1,
}
});
redbird.register('domain2.net', 'http://127.0.0.1:3003', {
ssl: {
port: 3003,
key: 'ssl/domain2/private.key',
cert: 'ssl/domain2/domain2.chained.crt',
secureOptions: constants.SSL_OP_NO_TLSv1 | constants.SSL_OP_NO_TLSv1_1,
}
});
Of the 3 files downloaded from ZeroSSL, whatsmychaincert.com put the certificate.crt and the ca_bundle.crt (in that order) into one file called domain.chained.crt (as see in the script above).

Is there a workaround in the nodemailer package for other services?

I noticed by looking at nodemailer docs that they didn't support unoeruo mails as a service. Is there a workaround or do i need to use another package. And if i need to use another is there anyone you recommend?
The "well know services" are just for your convenience. You can always create the SMTP Transport on your own, while using the settings from unoeuro
Assuming you are using typescript, it would look like this. Just set user and pass to your credentials:
import * as Smtp from 'nodemailer';
const options = {
host: "websmtp.unoeuro.com",
port: 587,
secure: true,
auth: {
user: "YOUR-LOGIN",
pass: "YOUR-PASSWORD"
};
};
const transport = Smtp.createTransport(options);
//do something with transport:
transport.sendMail({...});

Resources