如何跳过 winSCP 在自动脚本中询问凭据?

问题描述 投票:0回答:1

我刚开始使用 winSCP 和 Windows 任务计划程序。我正在努力连接到外部 FTP 服务器并将其内容复制到我的 PC 上的本地目录。

运行我的计划任务时,winSCP 会提示我提供连接到 FTP 服务器的凭据。如果我按 Enter 键并且不提交任何内容,程序将按预期运行并将所有文件复制到我的本地目录。如果我不交互,程序就会超时并且无法完成。

如何消除连接到服务器时输入凭据的需要?我希望这项任务能够完全自动化。我假设我可以在脚本文件中添加一行来自动执行此操作?

这是我的 winSCP 默认设置:(https://i.sstatic.net/UltbfzED.png)

这是我的 Windows 任务计划程序提示的操作: 行动:启动一个程序 程序/脚本:C:\Users urmand1\AppData\Local\Programs\WinSCP\WinSCP.com 添加参数: /log="C:\Users urmand1\Desktop\Log\winscp.log" /script="C:\Users urmand1\Desktop\Script\Script.txt"

这是我通过 winSCP 运行的脚本文件:

# Connect
open 10.201.47.178
# Change directory
lcd C:\Users\furmand1\Desktop\FTP
# Download file to the local directory
mget *.*
# Disconnect
close
# Exit WinSCP
exit

这是如果我不交互,winSCP 返回的日志文件:

. 2024-06-24 16:27:59.663 --------------------------------------------------------------------------
. 2024-06-24 16:27:59.663 WinSCP Version 6.1.1 (Build 13736 2023-06-21) (OS 10.0.19045 – Windows 10 Enterprise)
. 2024-06-24 16:27:59.663 Configuration: HKCU\Software\Martin Prikryl\WinSCP 2\
. 2024-06-24 16:27:59.663 Log level: Normal
. 2024-06-24 16:27:59.663 Local account: NAM\furmand1
. 2024-06-24 16:27:59.663 Working directory: C:\WINDOWS\system32
. 2024-06-24 16:27:59.663 Process ID: 29132
. 2024-06-24 16:27:59.678 Ancestor processes: WinSCP, ...
. 2024-06-24 16:27:59.678 Command-line: "C:\Users\furmand1\AppData\Local\Programs\WinSCP\WinSCP.exe" /console=6.1.1 /consoleinstance=_21632_881 "/log=C:\Users\furmand1\Desktop\Log\winscp.log" "/script=C:\Users\furmand1\Desktop\Script\Script.txt" 
. 2024-06-24 16:27:59.678 Time zone: Current: GMT-4, Standard: GMT-5 (Eastern Standard Time), DST: GMT-4 (Eastern Daylight Time), DST Start: 3/10/2024, DST End: 11/3/2024
. 2024-06-24 16:27:59.685 Login time: Monday, June 24, 2024 4:27:59 PM
. 2024-06-24 16:27:59.685 --------------------------------------------------------------------------
. 2024-06-24 16:27:59.685 Script: Retrospectively logging previous script records:
> 2024-06-24 16:27:59.685 Script: open 10.201.47.178
. 2024-06-24 16:27:59.685 --------------------------------------------------------------------------
. 2024-06-24 16:27:59.685 Session name: 10.201.47.178 (Ad-Hoc site)
. 2024-06-24 16:27:59.685 Host name: 10.201.47.178 (Port: 21)
. 2024-06-24 16:27:59.685 User name:  (Password: No, Key file: No, Passphrase: No)
. 2024-06-24 16:27:59.685 Transfer Protocol: FTP
. 2024-06-24 16:27:59.685 Ping type: Dummy, Ping interval: 30 sec; Timeout: 15 sec
. 2024-06-24 16:27:59.685 Disable Nagle: No
. 2024-06-24 16:27:59.685 Proxy: None
. 2024-06-24 16:27:59.685 Send buffer: 262144
. 2024-06-24 16:27:59.685 UTF: Auto
. 2024-06-24 16:27:59.685 FTPS: None [Client certificate: No]
. 2024-06-24 16:27:59.685 FTP: Passive: Yes [Force IP: Off]; MLSD: Off [List all: Off]; HOST: Off
. 2024-06-24 16:27:59.685 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2024-06-24 16:27:59.685 Cache directory changes: Yes, Permanent: Yes
. 2024-06-24 16:27:59.685 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2024-06-24 16:27:59.685 Timezone offset: 0h 0m
. 2024-06-24 16:27:59.685 --------------------------------------------------------------------------
. 2024-06-24 16:27:59.701 Username prompt (no username provided)
< 2024-06-24 16:27:59.701 Script: Prompting for credentials...
< 2024-06-24 16:28:52.057 Script: Connecting to 10.201.47.178 ...
. 2024-06-24 16:28:52.057 Connecting to 10.201.47.178 ...
. 2024-06-24 16:28:52.073 Connected with 10.201.47.178. Waiting for welcome message...
< 2024-06-24 16:28:52.073 220 R-30iB mate FTP server ready. [LR V9.30P/27]
> 2024-06-24 16:28:52.073 USER 
< 2024-06-24 16:28:52.095 230 User logged in [NORM].
> 2024-06-24 16:28:52.095 SYST
< 2024-06-24 16:28:52.095 215 UNKNOWN [LR V9.30P/27].
> 2024-06-24 16:28:52.095 FEAT
< 2024-06-24 16:28:52.111 500 Command not understood.
< 2024-06-24 16:28:52.111 Script: Connected
. 2024-06-24 16:28:52.111 Connected
. 2024-06-24 16:28:52.111 --------------------------------------------------------------------------
. 2024-06-24 16:28:52.111 Using FTP protocol.
. 2024-06-24 16:28:52.111 Doing startup conversation with host.
< 2024-06-24 16:28:52.111 Script: Starting the session...
> 2024-06-24 16:28:52.111 PWD
< 2024-06-24 16:28:52.111 257 "md:\" is current directory.
. 2024-06-24 16:28:52.111 Getting current directory name.
. 2024-06-24 16:28:52.111 Startup conversation with host finished.
< 2024-06-24 16:28:52.111 Script: Session started.
< 2024-06-24 16:28:52.111 Script: Active session: [1] 10.201.47.178
< 2024-06-24 16:28:52.111 Script: Terminated by user.
. 2024-06-24 16:28:52.111 Script: Exit code: 1
. 2024-06-24 16:28:52.126 Disconnected from server
ftp winscp windows-task-scheduler
1个回答
0
投票

winSCP 可以在 winSCP.exe 中生成自己的脚本,我在手动连接后用它来更新我的自动脚本。更新后的脚本是:

# Connect
open ftp://user:[email protected]/ -rawsettings FtpForcePasvIp2=1 FtpUseMlsd=1 FtpListAll=1 FtpHost=1
# Change directory
lcd C:\Users\furmand1\Desktop\FTP
# Download file to the local directory
mget *.*
# Disconnect
close
# Exit WinSCP
exit

要生成您自己的脚本,请通过 winSCP.exe 登录到您的 FTP 服务器,转到选项卡,转到生成会话 URL/代码,然后转到脚本。

© www.soinside.com 2019 - 2024. All rights reserved.