从 SSH 服务器下载文件的脚本

从 SSH 服务器下载文件的脚本

是否可以创建一个脚本,该脚本遵循 FileZilla 连接到 ssh 服务器时执行的相同命令?

当我使用 FileZilla 手动登录时,我收到以下连接类型的以下消息:

The server's host key is unknown. You have no guarantee that the server is the
computer you think it is.


    Host:  securedomain_1.com:22
    Fingerprint: ssh-dss 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx

    Host:  securedomain_2.com:22
    Fingerprint: ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx

    Host:  securedomain_3.com:22
    Fingerprint: ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx


Trust this host and carry on connecting?
[ ] Always trust this host, add this key to the cache.
[OK] [CANCEL]

我单击“确定”并且不将密钥添加到缓存中...

当我手动登录时,FileZilla 执行以下命令:

Status: Connecting to my.secure.site.com...
Response:   fzSftp started
Command:    open "[email protected]" 22
    [asks for key...]
    [I manually click OK]
Command:    Trust new Hostkey: Once
Command:    Pass: ********
Status: Connected to my.secure.site.com
Status: Retrieving directory listing...
Command:    cd "/SFTP/DIR"
Response:   New directory is: "/SFTP/DIR"
Command:    ls
Status: Listing directory /SFTP/DIR
Status: Calculating timezone offset of server...
Command:    mtime "IN"
Response:   1412312345
Status: Timezone offsets: Server: -18000 seconds. Local: -18000 seconds. Difference: 0 seconds.
Status: Directory listing successful

当我单击“确定”以“信任此主机并继续连接”时,究竟发生了什么?

我是否接受来自 SSH 服务器的密钥?

这适用于 Windows 机器。我原本想使用 WinSCP,但我想了解连接到这些服务器时发生了什么。我有一些用于 FTPS 的脚本,但对于这些服务器来说不起作用。

答案1

连接到 SSH 服务器时,你需要验证您是否信任服务器的主机密钥。这是为了防止中间人攻击

WinSCP 脚本-hostkey,您可以使用open命令。

open sftp://user:[email protected]/ -hostkey="ssh-dss 2048 xx..."

参考:在哪里可以获取 SSH 主机密钥指纹来授权服务器?

这里有一份指南将 Windows FTP 脚本转换为 WinSCP SFTP 脚本


关于 FileZilla 日志中的命令的注意事项:这些命令是专有命令psftp(FileZilla 在内部使用这些命令来实现 SFTP 协议)。它们与 SFTP 或 SSH 协议本身无关。显然,它们都在内部映射到一些 SFTP 请求,您可以使用 WinSCP 脚本模拟它们。但 WinSCP 命令会有所不同。还请注意,与 FTP 相反,SFTP 是一种二进制协议,因此没有像 FTP 中的文本命令(cdpwd等)。

相关内容