Elixir/Phoneix - SFTPClient 连接错误

Elixir/Phoneix - SFTPClient Connection Error

我打算将 SFTPClient 库集成到 DockerElixir/Phoenix 后端项目中以访问 SFTP 服务器。

使用 FileZilla,它与 OpenSSH 私钥完美配合。

但是使用库,它没有连接到服务器和returns奇怪的错误消息。

options = %{
      host: "",
      port: ,
      user: "",
      password: "",
      private_key_path: "",
      connect_timeout: 60000,
    }

SFTPClient.connect(options)

错误信息:

protocol: String.Chars
{:badmatch,
 {:error,
  {:asn1,
   {{:invalid_value, 5},
    [
      {:asn1rt_nif, :decode_ber_tlv, 1, [file: 'asn1rt_nif.erl', line: 85]},
      {:"PKCS-FRAME", :decode, 2, [file: 'PKCS-FRAME.erl', line: 155]},
      {:public_key, :der_decode, 2, [file: 'public_key.erl', line: 239]},
      {SFTPClient.KeyProvider, :decode_private_key, 2,
       [file: 'lib/sftp_client/key_provider.ex', line: 44]},
      {:ssh_auth, :get_public_key, 2, [file: 'ssh_auth.erl', line: 145]},
      {:ssh_connection_handler, :is_usable_user_pubkey, 2,
       [file: 'ssh_connection_handler.erl', line: 1793]},
      {:ssh_connection_handler, :"-init_ssh_record/4-lc$^0/1-0-", 2,
       [file: 'ssh_connection_handler.erl', line: 477]},
      {:ssh_connection_handler, :init_ssh_record, 4,
       [file: 'ssh_connection_handler.erl', line: 476]},
      {:ssh_connection_handler, :init, 1, [file: 'ssh_connection_handler.erl', line: 412]},
      {:ssh_connection_handler, :init_connection_handler, 3,
       [file: 'ssh_connection_handler.erl', line: 374]},
      {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}
    ]}}}},
[
  {:public_key, :der_decode, 2, [file: 'public_key.erl', line: 243]},
  {SFTPClient.KeyProvider, :decode_private_key, 2,
   [file: 'lib/sftp_client/key_provider.ex', line: 44]},
  {:ssh_auth, :get_public_key, 2, [file: 'ssh_auth.erl', line: 145]},
  {:ssh_connection_handler, :is_usable_user_pubkey, 2,
   [file: 'ssh_connection_handler.erl', line: 1793]},
  {:ssh_connection_handler, :"-init_ssh_record/4-lc$^0/1-0-", 2,
   [file: 'ssh_connection_handler.erl', line: 477]},
  {:ssh_connection_handler, :init_ssh_record, 4, [file: 'ssh_connection_handler.erl', line: 476]},
  {:ssh_connection_handler, :init, 1, [file: 'ssh_connection_handler.erl', line: 412]},
  {:ssh_connection_handler, :init_connection_handler, 3,
   [file: 'ssh_connection_handler.erl', line: 374]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}
]

答案: 参考i22-digitalagentur/sftp_client#11,OpenSSH密钥不能用于当前的库,所以,我使用命令将当前的OpenSSH密钥转换为PEM格式。

ssh-keygen -p -N "" -m pem -f ./key(=keypath)

终于找到解决当前 SFTPClient 库问题的方法了。

参考https://github.com/i22-digitalagentur/sftp_client/issues/11,OpenSSH密钥不能与当前库一起使用,所以,我使用命令将当前OpenSSH密钥转换为PEM格式。

ssh-keygen -p -N "" -m pem -f ./key(=keypath)