Can't upload files to HubSpot via FTP


#1

I am attempting to use the HubSpot FTP service to upload files to my portal's Design Manager. I am using Node.js, particularly the promise-ftp package. My code looks like this:

var PromiseFtp = require('promise-ftp');
var ftp = new PromiseFtp();

ftp.connect({
	host: "ftp.hubapi.com",
	port: 3200,
	user: USERNAME,
	password: PASSWORD,
	secure: true,
	debug: console.log
}).then(function(serverMessage) {
	console.log('Server message: ' + serverMessage);
	let file = fs.createReadStream('/path/to/local.css');
    return ftp.put(file, '/portals/path/to/remote.css');
}).then(function(list) {
	console.log('Directory listing: ');
	console.log(list);
	return ftp.end();
}).catch(function(err) {
	console.log("There was an error", err);
});

Sometimes I get a transfer 226 FTP code, which means file uploaded, but when I check on my design manager I only see an empty HTML header and not my actual css file. However, most of the time I get an error 425 which means can't establish data connection. Regardless of the error, I get a socket hang up error and the file upload never actually works.

The interesting thing is, GET requests work just fine. I can use ftp.list to return a list of all the files in a directory and even download them, but I can't upload them. This only happens programmatically too - I can use a FTP client like FileZilla or CyberDuck and the file upload works just fine, but I can't ever get it to work correctly using FTP. I realize 4xx codes are client-side, so if anyone know what I'm doing wrong in my code please feel free to correct me.

Thanks in advance!

Edit: added FTP debugging information.

[connection] > 'STOR /portals/path/to/remote.css'
[connection] < '150 File status okay; about to open data connection.\r\n'
[parser] < '150 File status okay; about to open data connection.\r\n'
[parser] Response: code=150, buffer='File status okay; about to open data connection.'
[connection] < '226 Transfer complete.\r\n'
[parser] < '226 Transfer complete.\r\n'
[parser] Response: code=226, buffer='Transfer complete.'
There was an error { Error: socket hang up
at TLSSocket.onHangUp (_tls_wrap.js:1135:19)
at emitNone (events.js:111:20)
at TLSSocket.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1055:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
code: 'ECONNRESET',
path: undefined,
host: 'ftp.hubapi.com',
port: undefined,
localAddress: undefined }

[connection] > 'STOR /portals/path/to/remote.css'
[connection] < '150 File status okay; about to open data connection.\r\n'
[parser] < '150 File status okay; about to open data connection.\r\n'
[parser] Response: code=150, buffer='File status okay; about to open data connection.'
[connection] < '425 Can't open data connection.\r\n'
[parser] < '425 Can't open data connection.\r\n'
[parser] Response: code=425, buffer='Can't open data connection.'
There was an error { Error: socket hang up
at TLSSocket.onHangUp (_tls_wrap.js:1135:19)
at emitNone (events.js:111:20)
at TLSSocket.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1055:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
code: 'ECONNRESET',
path: undefined,
host: same as above,
port: undefined,
localAddress: undefined }