I tried to upload and download files to-from to SFTP via script without success, I was intended with FileZilla although it is an excellent GUI tool I could not create a script. Recently I found a very good tool called WINSCP this is a Client for FTP and SFTP. It could used as GUI Client or as command tool with scripts. In my case I use it as a SFTP Client in order to create an script to upload files automatically all days.
If you need the tool go to the following link:
http://winscp.net/eng/index.php
This is an example on how to upload a file, on the last link you can find more examples:
# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option
confirm off
# Connect using a password
open sftp://user@example.com -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
option transfer binary
put C:\temp\File01.exe
# Disconnect
close
# Exit WinSCP
exit
Save the last is script as UPloadFile.txt
Then we need to create a Batch file to call the last script and to invoke the WinSCP client, type the following on notepad or other text editor and save as Upload.bat
"C:\Program Files (x86)\WinSCP\winscp.exe" /console /script=c:\UPloadFile.txt
Finally create a Schedule Task on Windows and on that invoke the Upload.bat file
It is important to note that the line with xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx must be replaced with the Host's key. If you don't now how to obtain this key, you can use the WinSCP GUI and connect to the SFTP server and take note from the first message that server returns, it is a screen like this:
I hope this example helps other people.
- Blogger Comment
- Facebook Comment
Subscribe to:
Post Comments
(
Atom
)
0 comentarios:
Post a Comment