This is an old revision of the document!

Documentation » Using WinSCP » Guides » Cloud Computing »

Injecting SFTP or FTP URL to a page (Amazon EC2 management console)

If you are managing a large amount of servers, it may not be possible for you to save a site for each of them in WinSCP. If your management portal offers an SFTP or FTP URL for each server, you can simply click it as WinSCP registers to handle the URLs. But if the URL is not available, as is the case with Amazon EC2 management console, you may end up copying the host name from management portal to WinSCP all the time.

Instead your may use a user script that automatically converts the host name on the management portal into a clickable URL.

Advertisement

A user script is a JavaScript code that is automatically run for a selected pages and can modify the page according to user’s needs.

Example for Amazon EC2 Management Console

Following functional example injects “Open in WinSCP” link next to Public DNS field on Instances page of Amazon EC2 console.

The user script is available for download: WinSCP_SFTP_URL_for_Amazon_EC2.user.js. If you have Greasemonkey extension installed in Mozilla Firefox, just click the link to install the script.

// ==UserScript==
// @name        WinSCP SFTP URL for Amazon EC2
// @namespace   http://winscp.net/
// @description Adds link "Open in WinSCP" next to "Public DNS" field on Instances page of Amazon EC2 console
// @include     https://*console.aws.amazon.com/*
// @icon        http://winscp.net/pad/winscp.png
// @version     1.0
// @grant       none
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
// ==/UserScript==
 
setInterval(
    function () { waitForHostNameElements (); },
    500
);
 
function waitForHostNameElements()
{
    var targetNodes = $('span:contains("Public DNS:")');
    
    if (targetNodes && targetNodes.length > 0) {
        targetNodes.each ( function () {
            // link not added yet
            if ($(this).html().indexOf('sftp://') < 1) {
                // Retrieve hostname
                var hostname = $(this).text().replace("Public DNS:", "").trim();
                // Change the username  if needed
                var username = "ec2-user"; 
                $(this).append(' &ndash; <a href="sftp://' + username + '@' + hostname + '/">Open in WinSCP</a>');
            }
        } );
    }
}

Advertisement

Last modified: by martin