WinSCP自動執行指令碼

來源:互聯網
上載者:User

標籤:io   os   ar   使用   sp   檔案   on   log   代碼   

我們經常使用WinSCP工具通過sftp協議上傳擷取檔案,本文描述通過bat批量處理檔案。

首先,我們開啟dos命令視窗使用 cd \d :D\WinSCP 開啟WinSCP安裝目錄

上傳檔案:

winscp.exe /console /command "option batch continue" "option confirm off" "open sftp://user:[email protected]:port" "option transfer binary" "put D:\需要上傳的檔案路徑 /伺服器檔案存放目錄" "exit" /log=log_file.txt

這裡為了方便理解,一一解釋。

winscp421.exe /console /command     命令名
 "option batch continue"           預設批處理  
 "option confirm off"             關閉提示資訊
"open ftp://user:[email protected]:port"  user:訪問使用者名稱 ,pwd:使用者密碼 ,ip:ip地址,port:連接埠號碼  預設22
"option transfer binary"   使用二進位格式傳送

log=log_file.txt 記錄檔地址
 "exit"                     ::執行完命令後退出 

注意:以上 command 後的都為參數 需在一行體現  如想分開寫 可把命令單獨放到一個檔案

如:aa.txt

option echo off
option transfer binary
open <sftp_or_ftp>://<user>:<password>@<host_ip>:<port> -privatekey <private_key_file>
cd <remote_dir>
put *.doc
exit

用命令執行該指令碼:winscp /script=aa.txt /ini=<WinSCP.ini_location> /log=<log_file>
如果需要配置傳輸參數,在WinSCP.ini配置,例如PreserveTime=0保持源檔案的時間戳記

 

下載檔案:

一下是下載檔案代碼,同上傳一樣,如需單獨寫指令碼可 用如上方式單獨儲存指令碼執行。

CD /d D:\WinSCP
winscp.exe /console /command "option batch continue" "option confirm off" "open sftp://root:[email protected]:22" "option transfer binary" "get /test.txt D:\sftptest\" "exit" /log=D:\sftptest\log.txt

 

WinSCP自動執行指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.