I am going to integrate the SFTPClient library into Docker
ized Elixir/Phoenix
backend project for accessing the SFTP server.
Using FileZilla, it was working perfectly with the OpenSSH private key.
But using the library, it doesn't connect to the server and returns weird error messages.
options = %{
host: "",
port: ,
user: "",
password: "",
private_key_path: "",
connect_timeout: 60000,
}
SFTPClient.connect(options)
Error messages:
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]}
]
Answer: Referring to i22-digitalagentur/sftp_client#11, OpenSSH key won't work with the current library, so, I used command to convert the current OpenSSH key into PEM format.
ssh-keygen -p -N "" -m pem -f ./key(=keypath)
Finally figured out the way of fixing the current SFTPClient library issue.
Referring to https://github.com/i22-digitalagentur/sftp_client/issues/11, OpenSSH key won't work with the current library, so, I used command to convert the current OpenSSH key into PEM format.
ssh-keygen -p -N "" -m pem -f ./key(=keypath)