Automation WinSCP | How to Read/Write files from/to SFTP location
Create a text file which contains the step for connecting to SFTP
open sftp://username:password@ServerName/ -hostkey="ssh-rsa 2048 b2:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
# Change the remote directory
cd serverPath
# Upload the file to current working directory
get -filemask="*>=1H" DestinationLocation
# Disconnect
close
# Exit WinSCP
exit
# Change the remote directory
cd serverPath
# Upload the file to current working directory
get -filemask="*>=1H" DestinationLocation
# Disconnect
close
# Exit WinSCP
exit
Save this Code as File1.txt and place this in the folder where WINSCP.EXE is present.
OPEN : Open Connection
Username: your Username for SFTP server
Password: Password for SFTP server
ServerName : Server IP or Server Host name
hostkey: Its a key required to make connection to that server:
How to get HostKey : Run the Code Without entering the hostkey value/Tag
Command line will itself show you the hostkey.
serverPath: Example: cd /opt/app/ : Go to Required Path
DestinationLocation : Destination where you need to download the files
get -filemask="*>=1H" C:\TEMP\ : Get the files from location with are updated in last 24 hours and place them into C:\Temp Location
Now Start the Command Prompt at location where WINSCP.EXE exists
Run the following command: winscp.com /ini=nul /script=File1.txt
You are done :)
Comments
Post a Comment