廣告

2024 年 4 月
1234567
891011121314
15161718192021
22232425262728
2930  

彙整

呼叫外部程式達成SFTP連線

出處https://dotblogs.com.tw/jean/2013/11/06/126876

有些早期舊程式語言並沒有支援SFTP元件,可透過呼叫外部程式來達成


SFTP
使用WinSCP

SFTP使用WinSCP

WinSCP目前是免費的FTP軟體

1. WinSCP網站下載WinSCP.exe

http://winscp.net/eng/download.php

2.產生Ftp.bat檔,檔案內容如下:

winscp.exe /console /script="C:\winscp\winscp-script.txt"

3.產生winscp-script.txt檔,檔案內容如下:

option batch abort
option confirm off
option transfer binary
open 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"
put d:\examplefile.txt
close
exit

說明:open sftp://登入帳號:登入密碼@FTP位址

-hostkey 用WINSCP.EXE連線後,在下圖紅框點兩下即可顯示

put 上傳檔案的本機路徑

clip_image001

另外說明 scp及ftps的語法:

winscp.exe scp://test@example.com:2222 /privatekey=mykey.ppk
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"

若寫在winscp-script.txt檔內則為

open scp://test@example.com:2222 /privatekey=mykey.ppk

open 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"

4.WinSCP.exeFtp.batwinscp-script.txt放在同一個目錄

clip_image002

5.執行Ftp.bat :Ftp.bat 點兩下即開始執行

讀者也會看的其它文章:

    Comments are closed.