Use Winscp Command Line
You can use the Winscp command line tool on a Windows platform to copy files to a remote location, much like you would with ftp/sftp/scp. From a windows command line prompt enter the following command, this connects as the user “opc” to a remote IP address using a private key file on the local file system
c:\winscp /console scp://opc@130.162.71.99 /privatekey=c:\tools\sftp_demo\test_file.ppk
Verbose Ouput :-
Opening session using command-line parameter in scripting is deprecated. Use ‘open’ command instead.
Searching for host…
Connecting to host…
Authenticating…
Using username “opc”.
Authenticating with public key “imported-openssh-key”.
Authenticated.
Starting the session…
Session started.
Active session: [1] opc@130.162.71.99
winscp>
winscp> ls
drwx—— 4 opc 500 4096 Feb 26 16:22:34 2018 .
drwxr-xr-x 14 root root 4096 Feb 27 16:19:25 2018 ..
-rw——- 1 opc opc 17624 Mar 9 12:43:03 2018 .bash_history
-rw-r–r– 1 opc 500 18 Mar 22 13:28:38 2017 .bash_logout
-rw-r–r– 1 opc 500 198 Jan 9 22:33:29 2018 .bash_profile
-rw-r–r– 1 opc 500 124 Mar 22 13:28:38 2017 .bashrc
-rw——- 1 opc opc 0 Jan 9 22:34:40 2018 .history
-rw-r–r– 1 root root 0 Feb 26 11:59:09 2018 .opc_init_first_
tag
drwxrwxr-x 2 opc opc 4096 Feb 26 15:56:17 2018 .oracle_jre_usag
e
drwx—— 2 opc opc 4096 Mar 2 10:44:49 2018 .ssh
You can then upload/put a file into the location
winscp> put c:\tools\sftp_demo\class.txt /home/opc/
Check the file got uploaded
winscp> ls class.txt
-rw-r–r– 1 opc opc 3994 Mar 8 18:10:49 2018 class.txt
Winscp Scripting
To script the copy of a file from a Windows platform to a Unix platform using Winscp, this can be achieved as follows. This uses command line winscp along with a parameter to pass in parameters from a script. Again this uses a private key, to avoid using usernames and passwords
winscp.com /console scp://opc@130.162.71.99 /privatekey=c:\tools\sftp_demo\test_file.ppk /script=c:\tools\sftp_demo\put_files.txt
The script file is simple, listed below, just a simple put command.
<put_files.txt>
put c:\tools\sftp_demo\class.txt /tmp/
exit
So the above script, places the local file class.txt onto the remote server using winscp/scp over port 22
Putty – pscp
With Putty command line tool installed, you can also use command line “pscp” command to copy files securely from a Windows Client to Unix using a private key file
Download putty and install https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
This copies local file test.txt to /tmp file system on remote host over port 22.
i.e.
pscp -i name_of_keyfile.ppk test.txt user@host:/tmp