【问题标题】:Automate connection to SFTP server (FileZilla)自动连接到 SFTP 服务器 (FileZilla)
【发布时间】:2017-08-07 15:44:31
【问题描述】:

我想自动连接到 SFTP 服务器 (FileZilla),以便创建批处理文件来自动执行某些报告流程。

到目前为止,我使用的是以下脚本:

sftp alessandro:arica.123@85.148.385.22

理论上,我在脚本上方传递用户名 (alessandro)、密码 (arica) 和主机名。问题是密码没有作为参数传递,因此为了连接,我被要求在终端中输入密码。

你能解释一下并告诉我我做错了什么吗?

【问题讨论】:

  • FileZilla 不是 SFTP 服务器。是什么让你的问题有点不清楚。

标签: batch-file automation sftp


【解决方案1】:

你能解释一下并告诉我我做错了什么吗?

sftp 的手册页这样解释sftp 命令的概要(缩写):

 sftp [...] [user@]host

如您所见,没有:password,因此username:password 都作为用户名传递给服务器。 sftp 命令不接受命令行密码,因为在脚本中以纯文本形式存储密码是非常糟糕的安全做法。

您应该将您的服务器配置为接受公钥身份验证(这并不难,而且对自动化非常有用!):

ssh-keygen -t rsa -f ~/.ssh/id_rsa
ssh-copy-id alessandro@85.148.385.22    # write password once
ssh alessandro@85.148.385.22            # will not ask for password again

【讨论】: