Search code examples
node.jsherokuftpstatic-ip-addressquotaguard

How to setup FTP static ip with QuotaGuard static?


I'm using a nodejs FTP client that's hosted on heroku, but the endpoint I'm connected to needs to whitelist my static IP. Heroku doesn't offer static IPs so I'm using the QuotaGuard addon. I'm a bit lost on how to use the QuotaGuard url to proxy my FTP connection.

I appreciate any help!


Solution

  • You can use a fork of the node-ftp package to do this but it isn't in NPM so requires a bit of manual install.

    1. Clone the repo locally: git clone [email protected]:choonyme/node-socksftp.git

    2. Copy the socksftp directory in to your project directory (e.g. cp -r node-socksftp/socksftp ./node_modules/

    3. export your QuotaGuard Static connection details in to a local env variable called QUOTAGUARDSTATIC_URL.

    You can then use all the same FTP commands as in the original node-ftp package.

    var url = require('url');
    var Client = require('socksftp');
    
    var httpProxyUrl = process.env.QUOTAGUARDSTATIC_URL;
    // Make sure to switch to the SOCKS5 proxy port 1080
    var socksProxyUrl = httpProxyUrl.replace(":9293",":1080");  
    
    var server = {
        'host': 'ftp.linuxjournal.com',
        'port': 21,
        'socksproxy': socksProxyUrl
    };
    
    var c = new Client();
    c.on('ready', function() {
        c.list(function(err, list) {
          if (err) throw err;
          console.dir(list);
          c.end();
        });
    });
    
    c.on('error', function(err){
        console.error('socksftp error: ' + err);
        return;
    });
    
    c.connect(server);
    

    For future reference you can contact our support team at http://support.quotaguard.com and we'll respond a bit quicker.