[从 StackOverflow 移出]
我们使用 PSFTP 以及 ppk 文件和批处理命令文件将 CSV 上传到远程 SFTP 主机。这已经运行了很多个月,直到最近 -b 参数才失败,并显示“严重:无法打开”
详细信息:
我们使用批处理文件或命令提示符在 Windows 上运行 PSFTP.exe。
我们通过 -b 参数传递的批处理命令文件名为“sftpcommands.txt”,包含以下几行:
put "D:\batch\Upload.csv"
quit
以下是我们从批处理文件或命令提示符运行的内容:
psftp.exe -v -P 22 -i D:\batch\keyfile.ppk -b D:\batch\sftpcommands.txt [email protected]
结果如下:
Looking up host "SFTPHost.domain.com" for SSH connection
Connecting to hostIP port 22
We claim version: SSH-2.0-PuTTY_Release_0.82
Connected to hostIP (from localIP:35022)
Remote version: SSH-2.0-AWS_SFTP_1.1
Using SSH protocol version 2
No GSSAPI security context available
Doing ECDH key exchange with curve nistp256, using hash SHA-256 (SHA-NI accelerated)
Host key fingerprint is:
ssh-rsa 4096 SHA256:ajIF+morestuffhere
Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
Initialised HMAC-SHA-256 (SHA-NI accelerated) outbound MAC algorithm
Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
Initialised HMAC-SHA-256 (SHA-NI accelerated) inbound MAC algorithm
Reading key file "D:\batch\keyfile.ppk"
Using username "OurUser".
Offered public key
Offer of public key accepted
Authenticating with public key "keynameinformation here"
Sent public key signature
Access granted
Opening main session channel
Remote debug message: SFTP: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Remote debug message: SFTP: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Opened main channel
Started a shell/command
Connected to some-host.server.transfer.us-east-1.amazonaws.com
Remote working directory is /
Fatal: unable to open
Session sent command exit status 0
Main session channel closed
All channels closed
现在奇怪的部分是:我们可以摆脱 -b 脚本语法,并sftpcommands.txt
在提示符出现时手动输入在文件中找到的相同命令psftp>
(例如):
psftp.exe -v -P 22 -i D:\batch\keyfile.ppk [email protected]
Looking up host "SFTPHost.domain.com" for SSH connection
Connecting to hostIP port 22
We claim version: SSH-2.0-PuTTY_Release_0.82
Connected to hostIP (from localIP:35022)
Remote version: SSH-2.0-AWS_SFTP_1.1
Using SSH protocol version 2
No GSSAPI security context available
Doing ECDH key exchange with curve nistp256, using hash SHA-256 (SHA-NI accelerated)
Host key fingerprint is:
ssh-rsa 4096 SHA256:ajIF+morestuffhere
Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
Initialised HMAC-SHA-256 (SHA-NI accelerated) outbound MAC algorithm
Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
Initialised HMAC-SHA-256 (SHA-NI accelerated) inbound MAC algorithm
Reading key file "D:\batch\keyfile.ppk"
Using username "OurUser".
Offered public key
Offer of public key accepted
Authenticating with public key "keynameinformation here"
Sent public key signature
Access granted
Opening main session channel
Remote debug message: SFTP: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Remote debug message: SFTP: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Opened main channel
Started a shell/command
Connected to some-host.server.transfer.us-east-1.amazonaws.com
Remote working directory is /
psftp> put "D:\batch\Upload.csv"
local:D:\batch\Upload.csv => remote:/Upload.csv
psftp> quit
Session sent command exit status 0
Main session channel closed
All channels closed
第三方几个月前确实移动了 SFTP 服务器,但据我所知,-b 参数在他们的新主机上仍然有效(但我可能错了)。
据我所知,我们这边没有任何变化,并且如所示,我们正在使用相同的本地登录 Windows 用户、相同的本地文件等进行 A/B 测试。应该不存在本地权限问题,因为我们使用的是 Windows,并且登录的帐户正在打开/编辑/访问所有相关文件。我还尝试将 -b 参数移动到行命令中的不同位置。
这个错误可能是远程 SFTP 服务器上的安全、配置或格式设置导致与 -b 命令文件混淆吗?
注意:我已经与操作远程 SFTP 主机的人员开具了一张票据,以对该问题进行三角测量,如果我能解决这个问题,我会在这里发布答案,以防它能帮助其他人看到 -b 开关上的“致命:无法打开”