Some thoughts/suggestions after using sftp
Anders Dahlin
anders@REDACTED
Tue Mar 23 14:31:47 CET 2010
Warning: Not all related to sftp.
Suggestion 1: The documentation could do with some examples and
description of prerequisites.
The first thing I did was trying to use it with password authentication,
like this:
ssh_sftp:start_channel(Host, Port, [{user, User},
{password, Pwd},
{silently_accept_hosts, true}]).
This resulted in {error,"Key exchange failed"}. After some debugging I
found that the real error was that ssh_file:add_host_key/3 tried to open
the known_hosts file. This did not exist, in fact I had no .ssh
directory at all, and file:open returned {error,enoent}.
Suggestion 2: Make ssh_file:add_host_key/3 create .ssh directory and
known_hosts if it does not already exist or at least give a better error
reason.
Next thing I did was accidentally give the user name as an atom. Of
course this is not correct but the error message I got was:
{error,[69,114,108,97,110,103,32,115,115,104,32,99,111,110,
110,101,99,116,105,111,110,32,104,97,110,100,108|...]}
So I did lists:flatten(element(2, v(-1))) and got this:
"Erlang ssh connection handler failed with reason: {badarg,\n
[{erlang,list_to_binary,\n
[username]},\n
{ssh_bits,enc,3},\n
{ssh_bits,encode,1},\n
{ssh_transport,\n
ssh_packet,2},\n
{ssh_connection_handler,\n
userauth,2},\n
{gen_fsm,handle_msg,7},\n
{proc_lib,\n
init_p_do_apply,3}]} , please report
this to erlang-bugs@REDACTED \n"
This message comes from ssh_connection_handler:terminate/3 and the
formatting is result of an old annoyance; There is no nice way of
getting a pretty result in io(_lib):format without using ~Xp, where X is
an arbitrary large number. I keep writing stuff like:
io_lib:format("~30000p\n", [Error]) because I want the pretty part
without the line breaks and indentation.
Suggestion 3: Add a control sequence to io(_lib):format/fwrite that
behaves as ~p but does not add line breaks and indentation.
Suggestion 4: And while we are in this region. Sometimes you really want
to create a flat formatted string and not a possibly deep io_list. How
about adding string:format/2, that behaves as
lists:flatten(io_lib:format(Format, Data))?
When I had the connection, I realized that the interface presented by
ssh_sftp does not use the standard (s)ftp command names and seems to be
lacking some basic functionality such as pwd and cd. You can get pwd
with the undocumented ssh_sftp:real_path/2,3.
Suggestion 5: Add the standard sftp command names (like cd, pwd, ls,
put, get etc) as functions in ssh_sftp.
/Anders
More information about the erlang-questions
mailing list