Differences

This shows you the differences between the selected revisions of the page.

guide_injecting_sftp_ftp_url_to_page 2015-03-04 guide_injecting_sftp_ftp_url_to_page 2024-03-18 (current)
Line 1: Line 1:
-~~NOINDEX~~ 
====== Injecting SFTP or FTP URL to a page (Amazon EC2 management console) ====== ====== 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 [[session_configuration#site|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 [[integration_url|registers to handle the URLs]]. But if the URL is not available, as is the case with [[guide_amazon_ec2|Amazon EC2]] management console, you may end up copying the host name from management portal to WinSCP all the time.+If you are managing a large amount of servers, it may not be feasible for you to [[session_configuration#site|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 [[integration_url|registers to handle the URLs]]. But if such %%URL%% is not available, as is a case with [[guide_amazon_ec2|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.+Instead, you may use a user script, that automatically converts the host name on the management portal into a clickable %%URL%%. 
 + 
 +~~AD~~
//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.// //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.//
Line 9: Line 10:
===== Example for Amazon EC2 Management Console ===== ===== 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.+Following functional example injects //"Open in WinSCP"// and //"Open in PuTTY"//((For //"Open in PuTTY"// link to work, you still need WinSCP installed, as WinSCP [[integration_putty#url|handles]] the ''%%ssh://%%'' URL.)) links next to //Public %%DNS%%// field on //Instances// page of Amazon EC2 management console.
-The user script is available for download: [[&winscp_root/download/WinSCP_SFTP_URL_for_Amazon_EC2.user.js|WinSCP_SFTP_URL_for_Amazon_EC2.user.js]]. If you have [[https://addons.mozilla.org/en-us/firefox/addon/greasemonkey/|Greasemonkey]] extension installed in Mozilla Firefox, just click the link to install the script.+&screenshotpict(ec2_url) 
 + 
 +The user script is available for download: [[&winscp_root/download/WinSCP_SFTP_URL_for_Amazon_EC2.user.js|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. 
 + 
 +  * For Mozilla Firefox, use [[https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/|Greasemonkey]] extension
 +  * For Google Chrome, use [[https://chromewebstore.google.com/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo|Tampermonkey]] extension.((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.))
<code javascript> <code javascript>
// ==UserScript== // ==UserScript==
-// @name        WinSCP SFTP URL for Amazon EC2 +// @name        WinSCP and PuTTY links for Amazon EC2 
-// @namespace  http://winscp.net/ +// @namespace  https://winscp.net/ 
-// @description Adds link "Open in WinSCP" next to "Public DNS" field on Instances page of Amazon EC2 console+// @author      WinSCP 
 +// @homepage    ~~SELF~~ 
 +// @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/* // @include    https://*console.aws.amazon.com/*
-// @icon        http://winscp.net/pad/winscp.png +// @icon        https://winscp.net/pad/winscp.png 
-// @version    1.0+// @version    2.0
// @grant      none // @grant      none
-// @require    http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js+// @require    https://code.jquery.com/jquery-3.2.1.min.js
// ==/UserScript== // ==/UserScript==
Line 33: Line 43:
{ {
    var targetNodes = $('span:contains("Public DNS:")');     var targetNodes = $('span:contains("Public DNS:")');
-····+
    if (targetNodes && targetNodes.length > 0) {     if (targetNodes && targetNodes.length > 0) {
        targetNodes.each ( function () {         targetNodes.each ( function () {
Line 40: Line 50:
                // Retrieve hostname                 // Retrieve hostname
                var hostname = $(this).text().replace("Public DNS:", "").trim();                 var hostname = $(this).text().replace("Public DNS:", "").trim();
-                // Change the username ·if needed +                // Ignore terminated instances 
- ···············var username = "ec2-user";  +                if (hostname != "-") { 
- ···············$(this).append(' &ndash; <a href="sftp://' + username + '@' + hostname + '/">Open in WinSCP</a>');+····················// Change the username if needed 
 + ···················var username = "ec2-user"; 
 +                   var uri = '://' + username + '@' + hostname + '/'; 
 + ···················$(this).append( 
 +························' &ndash; <a href="sftp' + uri + '">Open in WinSCP</a>' + 
 +                       ' &ndash; &lt;a href="ssh' + uri + '">Open in PuTTY</a>'); 
 +                }
            }             }
        } );         } );

Last modified: by martin