Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 01, 2015, 03:01:22 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: How to: upload screenshots to personal site (SFTP or FTP)  (Read 2468 times)

Vanav

  • Member
  • Joined in 2009
  • **
  • gravatar avatar
  • Posts: 13
    • View Profile
    • Donate to Member
How to: upload screenshots to personal site (SFTP or FTP)
« on: May 04, 2012, 09:34:25 AM »
You have your own site and want to upload screenshots to it. This small article describes how to do it.

You will need:
– personal site or any hosting with SFTP or FTP access. For example: virtual private server with SSH or FTP access.
– install Cygwin (easy).

You will got: after you click "Upload image" in Screenshot Captor, image will be uploaded and URL will be copied to clipboard, e.g. http://files.example.com/screenshots/20120504_162348_591_nMFnu4un.png
You can upload image in different ways:
- Main menu: SendToUpload image file with Uploader tool.
- Tray icon: Upload last image.
- New screenshot popup after capture: Send to...Upload image file with Uploader tool.
- Screenshot Captor floating toolbar: Select post-capture options and actions → [x] Upload screenshot.

Differences from ZUploader:
– ZUploader doesn't work for SFTP at all for me (as for v.5.5.0 r3030),
– random string is added to file name, so no one will be able to see your screenshots: you should give an exact link to it,
– screenshot is saved with single style of file naming: date_time_milliseconds_random.ext. This allows to order screenshots by date and resists to file name guessing.

I've tested three modes of upload (from most to less preferred):
1) upload using SFTP with public key,
2) upload using SFTP with password,
3) upload using FTP with password.
Some other upload protocols that are possible in "lftp" mode: FTPS, HTTP, HTTPS, HFTP, FISH, Torrent.

Steps for SFTP with public key

1. Run http://cygwin.com/setup.exe and install "openssh" in addition to base package. So you will have files "sftp.exe" and "date.exe" in folder "C:\Cygwin\bin".
2. Create SSH keys without password (press Enter twice) that will allow you to upload files:
Code: [Select]
> C:\Cygwin\bin\ssh-keygen -b 2048 -f automatic_access
Copy two new files to directory: "C:\Cygwin\home\UserName\.ssh\". As a result you should got two files: "C:\Cygwin\home\UserName\.ssh\automatic_access" and "automatic_access.pub".
3. Copy public key file "automatic_access.pub" to server to file "~/.ssh/authorized_keys"
4. Test your setup:
Code: [Select]
> C:\Cygwin\bin\sftp -i ~/.ssh/automatic_access username@files.example.com
"username" is your login to server, "files.example.com" is your site domain.
You should got:
Code: [Select]
Connected to files.example.com
sftp>
Type "quit".

Example of server configuration:
– home directory of site: ~/ (e.g. /home/sites/files.example.com/)
– public ssh key: ~/.ssh/authorized_keys
– some directory for screenshots: http://files.example.com/screenshots/ matches to path on server ~/data/screenshots/
So, if you put file to ~/data/screenshots/screenshot.png you will be able to see it here: http://files.example.com/screenshots/screenshot.png

5. Update variables in upload.bat (file is below) to match your configuration:
Code: [Select]
set pathToCygwinBin=C:\Cygwin\bin
set urlPathPrefix=http://files.example.com/screenshots
set serverPathPrefix=/data/screenshots
set remoteServer=files@files.example.com
set uploadMode=sftp
set privateKey=~/.ssh/automatic_access

6. Main menu: EditPreferencesExternal Tools - Custom Uploader Tool: specify path to "upload.bat".
In same window: Online Uploading → (*) Use custom uploader.

Now command "Upload image" will upload screenshot to your site and will copy URL to it to clipboard.

Steps for SFTP with password

1. Run http://cygwin.com/setup.exe and install "lftp" in addition to base package. So you will have files "lftp.exe" and "date.exe" in folder "C:\Cygwin\bin".
2-4. Skip.
5. Update variables in upload.bat (file is below) to match your configuration:
Code: [Select]
set pathToCygwinBin=C:\Cygwin\bin
set urlPathPrefix=http://files.example.com/screenshots
set serverPathPrefix=/data/screenshots
set remoteServer=sftp://login:password@files.example.com
set uploadMode=lftp
(notice "uploadMode" variable is changed)

Steps for FTP with password

1. Run http://cygwin.com/setup.exe and install "lftp" in addition to base package. So you will have files "lftp.exe" and "date.exe" in folder "C:\Cygwin\bin".
2-4. Skip.
5. Update variables in "upload.bat" (file is below) to match your configuration:
Code: [Select]
set pathToCygwinBin=C:\Cygwin\bin
set urlPathPrefix=http://files.example.com/screenshots
set serverPathPrefix=/data/screenshots
set remoteServer=ftp://login:password@files.example.com
set uploadMode=lftp
(notice "uploadMode" variable is changed)

upload.bat:
Spoiler
Code: Text
  1. @echo off
  2.  
  3. rem Depends on Cygwin: date, sftp (openssh) or lftp
  4.  
  5. set pathToCygwinBin=C:\Cygwin\bin
  6. set urlPathPrefix=http://files.example.com/screenshots
  7. set serverPathPrefix=/data/screenshots
  8. set remoteServer=files@files.example.com
  9. rem uploadMode=sftp for SFTP with public key or uploadMode=lftp in other cases.
  10. set uploadMode=sftp
  11. set privateKey=~/.ssh/automatic_access
  12.  
  13. rem Don't warn about Windows path scheme.
  14. set CYGWIN=nodosfilewarning
  15.  
  16. set source=%1
  17.  
  18. if exist %source% (
  19.     rem file exists
  20. ) else (
  21.     echo Error: file %source% doesn't exist.
  22.     exit
  23. )
  24.  
  25. rem Get full name of file.
  26. for /F "tokens=*" %%A in ('dir /L /B %source%') do set Variable=%%A
  27. rem Get file extension in lowercase.
  28. for %%i in ("%Variable%") do set sourceExt=%%~xi
  29.  
  30. rem Generate random string.
  31. setlocal EnableDelayedExpansion
  32. set _RNDLength=8
  33. set _Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
  34. set _Str=%_Alphanumeric%987654321
  35. :_LenLoop
  36. if not "%_Str:~18%"=="" set _Str=%_Str:~9%& set /A _Len+=9& goto :_LenLoop
  37. set _tmp=%_Str:~9,1%
  38. set /A _Len=_Len+_tmp
  39. set _count=0
  40. set _RndAlphaNum=
  41. :_loop
  42. set /a _count+=1
  43. set _RND=%Random%
  44. set /A _RND=_RND%%%_Len%
  45. set _RndAlphaNum=!_RndAlphaNum!!_Alphanumeric:~%_RND%,1!
  46. if !_count! lss %_RNDLength% goto _loop
  47.  
  48. rem Get current time.
  49. for /F "tokens=*" %%A in ('%pathToCygwinBin%\date +%%Y%%m%%d_%%H%%M%%S_%%N') do set Variable=%%A
  50. set FileTime=%Variable:~0,19%
  51.  
  52. rem Compose new file name.
  53. set NewName=%FileTime%_!_RndAlphaNum!!sourceExt!
  54. set destination="%serverPathPrefix%/!NewName!"
  55.  
  56. set url=%urlPathPrefix%/!NewName!
  57. rem Copy to clipboard without new line and trailing space.
  58. <nul set /p any-variable-name="%url%"| clip
  59. echo Url %url% was copied to clipboard.
  60.  
  61. rem Convert file path for Cygwin and add quotes.
  62. set source=%source:\=/%
  63. rem Remove existen quotes if any, and add quotes.
  64. set source="%source:"=%"
  65. rem Upload.
  66. if "%uploadMode%"=="sftp" (
  67.     echo put %source% %destination%| %pathToCygwinBin%\sftp -C -i %privateKey% %remoteServer%
  68. ) else (
  69.     echo put %source% -o %destination%| %pathToCygwinBin%\lftp %remoteServer%
  70. )
  71. rem pause
  72.  

« Last Edit: March 26, 2013, 05:23:37 PM by Vanav »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 34,967
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Donate to Member
Re: How to: upload screenshots to personal site (SFTP or FTP)
« Reply #1 on: May 04, 2012, 10:43:34 AM »
Thank you so much for sharing that Vanav!  :up:

I'll make it so you can change the text of the "zuploader" menu.

Note that you can also make "tool" files that serve the same purpose and can be triggered from Tool menu -- the only real advantage there is that you can make multiple tools instead of using the one zuploader "slot".

Vanav

  • Member
  • Joined in 2009
  • **
  • gravatar avatar
  • Posts: 13
    • View Profile
    • Donate to Member
Re: How to: upload screenshots to personal site (SFTP or FTP)
« Reply #2 on: March 26, 2013, 05:18:45 PM »
Updated instructions for Screenshot Captor v4 and fixed some minor bugs in script.

Stephen66515

  • Animated Giffer in Chief
  • Honorary Member
  • Joined in 2010
  • **
  • Posts: 2,998
    • View Profile
    • Donate to Member
Re: How to: upload screenshots to personal site (SFTP or FTP)
« Reply #3 on: March 26, 2013, 05:25:16 PM »
Updated instructions for Screenshot Captor v4 and fixed some minor bugs in script.

+1 For all that info!

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 34,967
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Donate to Member
Re: How to: upload screenshots to personal site (SFTP or FTP)
« Reply #4 on: March 26, 2013, 05:25:31 PM »
Terrific.

Note that even if you don't want to use this tool as *the* "uploader" tool, you can still configure it in same exact way as an item in the tool menu.

(Maybe someone wants to make a self package with compiled binaries and an .sctool so it can just be downloaded and added to SC tools folder and is ready for use?)