SFTP file upload to Web Server and automatically copy it’s URL to clipboard

Advertisement

adroman
Joined:
Posts:
4

SFTP file upload to Web Server and automatically copy it’s URL to clipboard

Dear Friends, I love WinSCP and I have a question for you.
I want to be able to automatically upload image file to Apache Web Server with secure SFTP protocol and automatically copy it’s URL right to the clipboard.
I have an Apache Web Server with address for example: https://example.com
I’m able to upload a file with WinSCP SFTP script to the Web Server root folder but could you please help me with automatic insertion of it’s URL to the clipboard.
For example, I want my clipboard to keep this URL: https://example.com/filename.jpg
Here’s my SFTP upload script for a single file:
# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect to server (change this to match your connection settings)
open sftp://myuser:mypassword@example.com
# Apache web-server directory 
cd "/C:/xampp/htdocs"
# Upload the file to current working directory
put %1% 
# Disconnect
close
# Exit WinSCP
Exit

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
37,591
Location:
Prague, Czechia

Re: SFTP file upload to Web Server and automatically copy it’s URL to clipboard

WinSCP scripting cannot generate an HTTP URL, nor can it copy anything to the clipboard.
But after WinSCP script finishes, you can use some other tool to do that.
Assuming your script runs from a Windows batch file, which takes the filename as a parameter, you can use Windows clip tool to do that:
winscp.com /command=yourscript.txt /parameter %1
echo https://example.com/%1| clip

Reply with quote

adroman
Joined:
Posts:
4

Re: SFTP file upload to Web Server and automatically copy it’s URL to clipboard

OK, thank you very much Sir for this valuable pointer. Please let's go a little bit further 😊
Actually, what I'm trying to accomplish is to to efficiently use WinSCP with Greenshot (most popular screenshot software).
There's a Greenshot manual https://getgreenshot.org/2013/11/07/how-to-upload-screenshots-to-a-web-server-via-ftp-scp-or-sftp/ how to securely upload a screenshot to Web Server. Works fine but no automatic insertion to clipboard. Their example doesn't use a “bat”-file, but maybe it can be used..
Of course, I also posted same question to Greenshot support forum but no response yet😬
Do you have any idea how to insert an URL in that scenario or it's not possible? 😊
Or maybe you know any other screenshot software where it can be done easier? 😵

Reply with quote

martin
Site Admin
martin avatar

Re: SFTP file upload to Web Server and automatically copy it’s URL to clipboard

So create the batch file. Make it call both winscp and clip, as I have shown above (you will need to use absolute path to winscp.com, the same way the Greenshot example does. And make Greenshot call the batch file. Either it can take batch file path directly as a "Command". And if not, it should be able to take cmd.exe as the Command and /c C:\path\the_batch_file.bat as its Argument.

Reply with quote

Advertisement

You can post new topics in this forum