-2

SFTPサーバー内のすべてのファイルをリストし、それをファイルに出力するスクリプトがあります(別のスクリプトで使用されます)。必要な出力を生成するコマンドは次のとおりです。

echo ls | psftp -l myusername -pw mycomplexpwd FTPServerHostname > C:/Users/myuser/Desktop/ls.txt

これは、Windows タスク スケジューラによって 1 日に数回呼び出されます。何らかの理由で、このコマンドを (.bat ファイルで) スケジュールし、 user を介して実行するSYSTEMと、出力ファイルには次の内容のみが含まれます。

Remote working directory is /
psftp> quit

別のユーザーを使用している場合、出力は期待どおりです (すべてのファイルのリスト)SYSTEMそれをスクリプト化し、そのシステムの残りのスクリプトと同じように実行できる方法が必要です。私も以下を試しました:

psftp -l myusername -pw mycomplexpwd FTPServerHostname < C:/Users/myuser/Desktop/lscmd.txt > C:/Users/myuser/Desktop/ls.txt

と:

psftp -l myusername -pw mycomplexpwd FTPServerHostname -b C:/Users/myuser/Desktop/lscmd.txt > C:/Users/myuser/Desktop/ls.txt

lscmd.txt には以下が含まれます。

ls

そして、動作は同じです。EDIT : 以下のMartinが示すように、以下は同じ出力を生成せず、ファイルに触れていない可能性があります。ただし、期待される結果は生成されませんでした。

必要な動作を行うためにできることはありますか?

OSはWindows Server 2012 R2です。

4

1 に答える 1

-1

そのため、最初の接続で sFTP サーバーを信頼する (または にキーを追加するHKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys) という追加の手順があることがわかります。私がそれを行った方法の(わずかな)詳細については、関連するserverfaultの質問を確認してください。echo ls | psftp -l myusername -pw mycomplexpwd FTPServerHostname > C:/Users/myuser/Desktop/ls.txtその後、と他のバリアント (例) の両方が-b機能しました。

編集:私の最大の問題は、SYSTEM何が起こっているのかをデバッグできるようにcmdを取得することだったと思います. 参照とより明確にするために(説明なしで反対票を投じられたため!)、以下はキーを追加する前のコマンドの出力であり、機密部分をマスクしただけRemote working directory is /で、出力ファイルにあったメッセージを受け取ったことを示しています。

C:\Users\myuser>echo ls | psftp -l myftpuser -pw mycomplexpswd sftp_server
The server's host key is not cached. You have no guarantee
that the server is the computer you think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 SHA256: thecomplexfancyhostkey
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n, Return cancels connection, i for more info) 
Using username "myftpuser".
Pre-authentication banner message from server:
| Company FTP Login - Please enter valid credentials to continue
End of banner message from server
Keyboard-interactive authentication prompts from server:
End of keyboard-interactive prompts from server
Remote working directory is /
psftp> quit
于 2021-11-20T19:09:08.513 に答える