2016年11月22日 星期二

電腦 windows使用winscp的指令功能

在windows的cmd模式,使用ftp指令無法下載。
決定使用winscp來取代。

建立參數檔:script.txt
option batch abort
option confirm off
option transfer binary
open ftp://LoginID:LogPwd@FTP_Host
put d:\examplefile.txt
close
exit

建立執行檔:ftp.bat
winscp.com /script=\script.txt /ini=nul /log=\session.log

將ftp.bat、script.txt放在winscp資料夾
執行ftp.bat即可。也可寫入排程固定執行。



使用sftp
sftp://LoginID:LogPwd@FTP_Host -hostkey="ssh-rsa 1024  XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:X:XX:XX:XX:XX"

使用scp
winscp.exe scp://test@example.com:2222 /privatekey=mykey.ppk

使用ftps
winscp.exe ftps://martin@example.com /implicit /certificate="xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"

參考資料:
SFTP使用WinSCP
Useful Scripts
Scripting and Task Automation
Example
In the example below, WinSCP connects to example.com server with account user, downloads file and closes the session. Then it connects to the same server with the account user2 and uploads the file back.
# Connect
open sftp://user:password@example.com/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
# Change remote directory
cd /home/user
# Force binary mode transfer
option transfer binary
# Download file to the local directory d:\
get examplefile.txt d:\
# Disconnect
close
# Connect as a different user
open sftp://user2:password@example.com/
# Change the remote directory
cd /home/user2
# Upload the file to current working directory
put d:\examplefile.txt
# Disconnect
close
# Exit WinSCP
exit
Save the script to the file example.txt. To execute the script file use the following command.
winscp.com /ini=nul /script=example.txt
==
For simple scripts you can specify all the commands on command-line using /command switch:
winscp.com /ini=nul /command "open sftp://user:password@example.com/ -hostkey=""ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx""" "get examplefile.txt d:\" "exit"
==
In Windows batch file, you can use ^ to split too long command-line to separate lines by escaping following new-line character:
winscp.com /ini=nul /command ^
    "open sftp://user:password@example.com/ -hostkey=""ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx""" ^
    "get examplefile.txt d:\" ^
    "exit"
See other useful example scripts.

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。