Ah...Windows, why you no easy?

SITREP:

  1. You have a Windows Machine ????.

  2. You have a linux machine ????.

  3. Sensitive data needs to get from 1 to 2 securely ????.

SOLUTION:

  1. Secure linux with SSH authentication.

  2. Install PuTTY.exe on Windows: https://the.earth.li/~sgtatham/putty/latest/x86/putty.exe.

  3. Install PSFTP.exe on Windows: https://the.earth.li/~sgtatham/putty/latest/x86/psftp.exe. But why not SPCP? Answer.

  4. Make SSH connection via Putty to linux machine using existing SSH keys. Be sure to give your site a simple name (eg somePuTTYsitename) rather than use its IP address in the Saved Sessions field. Guide here.

  5. Test PSFPT (this is all windows, btw): Open Start > Run > cmd.exe


    cd c:\psftp (or where ever you installed PSFTP).
    psftp
    Enter linux machine username.
    Enter SSH key passphrase
    cd /var/www/html/location/
    put c:\somelocalfilefromwindows.txt
    exit

  6. Check remote location on linux server via PuTTY.exe or Filezilla.

  7. Reward yourself with adult beverage (mandatory).


Lets make it automated. We'll set up a simple bat file so Windows can look there as a startup item. The bat file will trigger a Visual Basic (VB) script that replicates our manual command line structure. You'll need to replace the information with your own.

Batch file, save as whateveryouwant.bat:

@echo
title LAUNCH PSFTP TO UPLOAD INTO LIVE LINUX SERVER
wscript "c:\psftp\yourVisualBasicScript.vbs"

Add to Windows Statup entry, here how to do that on Windows 7/8/10: http://www.thewindowsclub.com/how-to-schedule-batch-file-run-automatically-windows-7

Create the VB script (that'll you place inside the psftp folder (or where ever you have it) on C: drive on Windows):

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe", 9

WScript.Sleep 500

WshShell.SendKeys "cd c:\psftp"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500

WshShell.SendKeys "psftp"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500

WshShell.SendKeys "open somePuTTYsitename"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500

WshShell.SendKeys "someLinuxuser"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500

WshShell.SendKeys "someSSHpassphrase"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500

WshShell.SendKeys "cd /somelinuxdirectory/"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500

WshShell.SendKeys "put c:\somewindowsdirectory\somefile.xxx"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500

WshShell.SendKeys "exit"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500

WshShell.SendKeys "exit"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500

Question: Why not use SPCP?

Answer: SPCP can only utilize putty generated keys, not OpenSSH keys your linux machine utilizes by default. Putty does have an SSH converted key file tool but since it changes the SSH key the linux machine will still [rightly] refuse it.

If you need help connecting your various Windows and Linux machines and safely transport data securely from a local machine and to the cloud (and vice-versa) gripfastistech.com can help! Ask a question below, comment or contact us directly to start the conversation!


 

About the Writer
Chris Lessley
Author: Chris Lessley
A server admin, dev ops warrior and website designer since 2002, Chris is a lover of all things Linux and open-source! Each blog topic has been tested by fire in the real world and shared with the hope to help others. Need more help? Hire me! Chris' other interests include fine art and the humanities in the classical tradition and can be found writing for our friends over at gripfastart.works. If you like this content, kindly consider donating to keep this website free to all, without ads.

Comments powered by CComment

Member of The Internet Defense LeagueOpen Source Initiative