從批次檔中執行 ftp 批次文件

從批次檔中執行 ftp 批次文件

我有一個計劃任務,每天都會執行檔案 ftp.txt 中的命令。該文件如下所示,它透過 ftp 連接到我的網站,並將 3 個 XML 檔案放到我的 Web 伺服器上。

命令:

ftp -s:filename

透過命令執行的文件

open ftp.mysite.co.uk
username
password
put C:\file.xml location/file.xml
put C:\file1.xml location/file1.xml
put C:\file2.xml location/file2.xml
bye

我現在必須執行相同的傳輸,但傳輸到具有不同 ftp 詳細資訊的網站。我不想為每次傳輸安排一個新的 Windows 任務,所以我想知道是否有一種方法可以從命令列觸發的主 ftp.txt 檔案執行其他 ftp.txt 檔案?如果這是不可能的,我可以從單一命令列命令執行多個 ftp 批次檔嗎?

答案1

你可以使用WinSCP作為腳本化 FTP 用戶端

的腳本功能WinSCP不支援任何控制序列、檔案路徑操作等。VB腳本)。任何支援的語言通訊/ActiveX可以使用。

例子來自 WinSCP 網站:

<job>
<reference object="WinSCP.Session" />
<script language="VBScript">

Option Explicit

' Setup session options
Dim sessionOptions
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
With sessionOptions
    .Protocol = Protocol_Sftp
    .HostName = "example.com"
    .UserName = "user"
    .Password = "mypassword"
    .SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
End With

Dim session
Set session = WScript.CreateObject("WinSCP.Session")

' Connect
session.Open sessionOptions

' Upload files
Dim transferOptions
Set transferOptions = WScript.CreateObject("WinSCP.TransferOptions")
transferOptions.TransferMode = TransferMode_Binary

Dim transferResult
Set transferResult = session.PutFiles("d:\toupload\*", "/home/user/", False, transferOptions)

' Throw on any error
transferResult.Check

' Print results
Dim transfer
For Each transfer In transferResult.Transfers
    WScript.Echo "Upload of " & transfer.FileName & " succeeded"
Next

' Disconnect, clean up
session.Dispose

</script>
</job>

修改這樣的腳本來滿足您的特定/動態需求。

相關內容