我有一个脚本,该脚本使用SCP从AWS上的远程Linux主机提取文件。在每晚运行相同代码约6个月而没有问题之后,今天它开始使用protocol error: filename does not match request
失败。我在以下一些更简单的文件名上重现了该问题:
$ scp -i $IDENT $HOST_AND_DIR/"foobar" .
# the file is copied successfully
$ scp -i $IDENT $HOST_AND_DIR/"'foobar'" .
protocol error: filename does not match request
# used to work, i swear...
$ scp -i $IDENT $HOST_AND_DIR/"'foobarbaz'" .
scp: /home/user_redacted/foobarbaz: No such file or directory
# less surprising...
用单引号引起来的原因是,我最初是使用名称中带有空格的文件。为了处理这些空格,我已经做了
$HOST_AND_DIR/"'foo bar'"
好几个月了,但是从今天开始,它将只接受$HOST_AND_DIR/"foo\ bar"
。因此,我的问题已解决,但我仍对正在发生的事情感到好奇。我在错误消息上搜索了Google,但没有看到任何真正的提及,这让我感到惊讶。
涉及的两个主机在
OpenSSL 1.0.2g
的输出中都有ssh -v localhost
,而bash --version
表示GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
有任何想法吗?
最佳答案
我最终查看了源代码,并发现了抛出此错误的提交:
GitHub Commit
remote->local directory copies satisfy the wildcard specified by the user.
This checking provides some protection against a malicious server sending unexpected filenames, but it comes at a risk of rejecting wanted files due to differences between client and server wildcard expansion rules.
For this reason, this also adds a new -T flag to disable the check.
他们添加了一个新的标记
-T
,它将忽略他们添加的这个新检查,因此它是向后兼容的。但是,我想我们应该查找并找出为什么我们使用的文件名被标记为受限文件。
关于ssh - scp失败,显示 “protocol error: filename does not match request”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54598689/