How to use windows command line to put a file to an SFTP location using Putty?
I have used hybrid approach to solve this problem.
Getting started:
- Download : (Putty)
- Basic knowledge of command line in Windows (Not must )
- You know the server you want to connect to
Step by Step:
- Download and install Putty. You can navigate to the path of Putty Installation, mostly it would be C:\Program Files\PuTTY .
- Start Command Prompt in windows, short cut (Windows + R), type CMD and hit enter .
- Try going to your Putty installation directory :
- Now since we have validated our installation let’s get to the main task now. Create text file a paste below to it and save the file as
.bat , I am saving it as Toolboxupload.bat Content of the FileToolboxupload.bat :
@ECHO OFF
ECHO *******************Hello World ************
cd C:\Program Files\PuTTY\
psftp -bc@ PAUSE
CLS
EXIT - Double click on the file see the output, it will say as shown below:Enter the password Now
Now you know you were able to connect to it by entering your password. Lets Put this in this script .
- Update the toolbox.bat file as below. Here I am putting the password in display area so that I can copy and paste while starting my activity .
- Code below :
@ECHO OFF
ECHO *******************Hello World ************
ECHO Copy PASSWORD:
cd C:\Program Files\PuTTY\
psftp -bc@
ECHO.
PAUSE
CLS
EXIT
- Code below :
- Output is now :
- Now let’s add our action that we want to do on to the SFTP server.
- I want to navigate to directory /upload and then upload a file there.
- Create another text file and say it myscript.scr (not .txt at the end)
- Now let put below code in this file myscript.scr :
- Now let’s change the code in your toolbox.bat to :
- Code as below :
@ECHO OFF
ECHO *******************Hello World ************
ECHO Copy PASSWORD: ADD YOUR PASSOWRD HERE
cd C:\Program Files\PuTTY\
psftp -bc@ -b myscript.scr
ECHO.
PAUSE
CLS
EXIT - Output you will see after you enter your password
- Now you are done add to upload a file to SFTP server add following line in myscript.scr file
put “
“
put “text.csv” - Now run your toolbox.bat , enter your password . all the command from myscript.scr will get executed after you enter you password. Enjoy your put command is now uploading the file to server.
Related
Give some Likes to Authors