No response from :ssh_sftp.list_dir/2 when given path other than root

Hello, new to elixir, just worked through almost all of the guide (inlcuding Mix/OTP) on the website and am now dipping my feet with a simple hobby project. Right out the gates, I’m having some trouble with :ssh_sftp.list_dir/2 and I’m not sure where it is hanging up.

I can connect to the server (using same credentials that work fine with Nautilus/WinSCP), and can list the contents of the root directory, but attempting to list with any path other than root it just hangs forever waiting for response.

:ssh_sftp.list_dir(pid, '')
#=> {:ok, ['dir1, 'dir2']}

:ssh_sftp.list_dir(pid, 'dir1')
#=> no response

:ssh_sftp.list_dir(pid, 'nope')
#=> {:error, :no_such_path}

As above, it correctly outputs a list of the directories in root, and returns :no_such_path if given an incorrect path. But never returns anything if given a valid non-root path. Is there something obvious I’m missing?

Thank you for any wisdom and advice you have time to offer!

I regret I have no wisdom to offer, but a quick look at the Erlang docs suggest that maybe try :ssh_sftp.list_dir(pid, 'dir1', 5000) and see if that times out or returns some different error? No response seems like, well, no response from the server.

Yes, it just times out if you give it a timeout (default is inf). Async/await with Task to give a timeout, similarly times out. So as far as I can tell the server simply never responds, however I know that my list_dir calls are able to “reach” arbitrarily deep directories since it only hangs when a valid path is given. It responds promptly with an error if the path does not lead to something real in the server.

any luck solving this problem? I’m running into the same issue.

1 Like

I had the same issue and fixed it by switching SFTP protocol to version 3 using sftp_vsn connection option. I think the 4 is the default and some older/misconfigured servers do not fully support it.


The “default” is the highest version the two parties both support. There is a buggy Java-based SFTP server out there that has version 4 as the highest version of SFTP it supports, and has a buggy implementation of version 4 to boot.

So setting sftp_vsn to 3 in general might actually degrade your performance with better SFTP servers, so ideally you’d only do it for broken servers like that Java-one.