バッチファイル内から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

使用できるウィンSCPとしてスクリプト FTP クライアント

のスクリプト機能は、WinSCP制御シーケンスやファイルパスの操作などをサポートしていません。これらが必要な場合は、別のスクリプト言語で実装されたラッパースクリプトからWinSCPスクリプトを呼び出す必要があります(VBスクリプト)。COM/アクティブXに使える。

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>

特定の動的なニーズに対応するために、このようなスクリプトを変更します。

関連情報