Differences
This shows you the differences between the selected revisions of the page.
guide_injecting_sftp_ftp_url_to_page 2015-03-05 | 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 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. | 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, you 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 an "Open in WinSCP" link next to //Public %%DNS%%// field on //Instances// page of Amazon EC2 management 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. |
+ | |||
+ | &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]]. | 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 and the download link above. | + | 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 Mozilla Firefox, use [[https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/|Greasemonkey]] extension; |
- | * For Google Chrome, use [[https://chrome.google.com/webstore/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 Stote.)) | + | * 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/ |
// @author WinSCP | // @author WinSCP | ||
- | // @homepage http://winscp.net/eng/docs/guide_injecting_sftp_ftp_url_to_page | + | // @homepage ~~SELF~~ |
// @description Adds an "Open in WinSCP" link next to "Public DNS" field on Instances page of Amazon EC2 management console | // @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 40: | 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 47: | 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(' – <a href="sftp://' + username + '@' + hostname + '/">Open in WinSCP</a>'); | + | ····················// Change the username if needed |
+ | ···················var username = "ec2-user"; | ||
+ | var uri = '://' + username + '@' + hostname + '/'; | ||
+ | ···················$(this).append( | ||
+ | ························' – <a href="sftp' + uri + '">Open in WinSCP</a>' + | ||
+ | ·······················' &ndash; <a href="ssh' + uri + '">Open in PuTTY</a>'); | ||
+ | } | ||
} | } | ||
} ); | } ); |