Contents » 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 feasible 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 such URL is not available, as is a case with Amazon EC2 management console, you may end up copying the host name from management portal to WinSCP all the time.

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

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 an “Open in WinSCP” link next to Public DNS field on Instances page of Amazon EC2 management console.

The user script is available for download: WinSCP_SFTP_URL_for_Amazon_EC2.user.js.

To install the script, install a user script manager to your browser and click on the download link above.

// ==UserScript==
// @name        WinSCP SFTP URL for Amazon EC2
// @namespace   https://winscp.net/
// @author      WinSCP
// @homepage    https://winscp.net/eng/docs/guide_injecting_sftp_ftp_url_to_page
// @description Adds an "Open in WinSCP" link next to "Public DNS" field on Instances page of Amazon EC2 management console
// @include     https://*console.aws.amazon.com/*
// @icon        https://winscp.net/pad/winscp.png
// @version     1.0
// @grant       none
// @require     https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/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>');
            }
        } );
    }
}
1) While Google Chrome supports user scripts on its own, it does not support @require directive, nor it runs scripts not available in Chrome Web Store.
 
  guide_injecting_sftp_ftp_url_to_page.txt · Last modified: by martin
 

Search Documentation

This page

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

Associations

Site design by Black Gate