Mats

Mats

Hi,
I’ve seen a couple of examples using the Erlang FTP client from Elixir and I have succesfully stepped through an example but now I’m stuck.
I keep getting an {:error, :epath} error although the file is there.

ftp_target_directory = ftp_target_directory |> String.to_charlist
ftp_host = Config.get(:importer, :ftp_host) |> String.to_charlist
ftp_user = Config.get(:importer, :ftp_user) |> String.to_charlist
ftp_pass = Config.get(:importer, :ftp_pass) |> String.to_charlist

Logger.info("Downloading files from #{inspect ftp_host} to #{inspect ftp_target_directory}")

:application.start :inets 
{:ok, pid} = :inets.start(:ftpc, host: ftp_host)
:ftp.user(pid, ftp_user, ftp_pass)
:ftp.pwd(pid)
:ftp.lcd(pid, ftp_target_directory)
:ftp.type(pid, :binary)
directory_list = get_listing(pid)
Enum.each(directory_list, fn directory ->
    :ftp.cd(pid, directory)
    files = get_listing(pid)
    Enum.each(files, fn file ->
      Logger.info("Downloading #{inspect file}")
      status = :ftp.recv(pid, file)
      Logger.info("Status #{inspect status}")
    end) 
    :ftp.cd(pid, '..')
end)
end

defp get_listing(pid) do
   {:ok, listing} = :ftp.nlist(pid)
   listing = listing |> String.Chars.List.to_string |> String.split("\r\n", trim: true)
   Enum.map(listing, fn item -> String.to_char_list(item) end)
end

I’ve put the client in verbose mode but I can’t see the client actually requesting the file, all I get is the error above.
I’m using the bitwalker/alpine-erlang:6.1 with elixir 1.4.

iex(testdownload@127.0.0.1)6> {:ok, pid} = :inets.start(:ftpc, host: ftp_host, verbose: true)
\n220 Welcome to the FTP Service."er (v. 7.2.0)
{:ok, pid<0.647.0>}
iex(testdownload@127.0.0.1)7> :ftp.user(pid, ftp_user, ftp_pass)
“Sending: USER secret”
“Receiving: 331 Password required for secret”
“Sending: PASS secretpass”
“Receiving: 230 Logon OK. Proceed.”
:ok
iex(testdownload@127.0.0.1)8> :ftp.pwd(pid)
“Sending: PWD”
“Receiving: 257 "/" is current directory.”
{:ok, ‘/’}
iex(testdownload@127.0.0.1)9> :ftp.lcd(pid, ftp_target_directory)
:ok
iex(testdownload@127.0.0.1)10> :ftp.type(pid, :binary)
“Sending: TYPE I”
“Receiving: 200 Type set to I”
:ok
iex(testdownload@127.0.0.1)11> :ftp.cd(pid, ‘files’)
“Sending: CWD files”
“Receiving: 250 CWD command successful.”
:ok
iex(testdownload@127.0.0.1)14> :ftp.nlist(pid)
“Sending: PASV”
“Receiving: 227 Entering Passive Mode (147,14,4,15,156,195)”
“Sending: NLST”
“Receiving: 150 Opening data connection for file list.”
“Receiving: 226 Transfer complete.”
{:ok, ‘file.csv\r\n’}
iex(testdownload@127.0.0.1)12> :ftp.recv(pid, ‘file.csv’)
{:error, :epath}

Can anyone tell me what I’m doing wrong? :slight_smile:

Showing Posts 1 to 6

NobbZ

NobbZ

The error you get is described as foolows:

epath
No such file or directory, or directory already exists, or permission denied.

So have you checked with another FTP client if you can download the file using that one? Also put it in verbose and check if it uses relative path to current dir or full path for RECV, change your code accordingly then.

Mats

Mats OP

Hi,
Thanks for your response.
I’ve successfully downloaded the file with the linux ftp client.
The problem with verbose mode is that when I try recv I get the error right away. It is as if the client doesn’t even issue the command.
I’m completely baffled. :slight_smile:

NobbZ

NobbZ

Please try to use :ftp.recv/3 and provide a path and filename that you are definitevely allowed to write. I’m not quite sure where BEAM will try to create the file if the third parameter is missing.

Mats

Mats OP

Just a quick follow up. It was indeed file system rights that were my problem.
I was building the release with a docker mix plugin that used the USER directive in the Dockerfile.
Everything works as expected now.

Thanks for your help!

the-mikedavis

the-mikedavis

I have also run into this when the ftp server deleted the file before I was able to download it (i.e. between running :ftp.nlist/1 and :ftp.recv/2)

jnmandal

jnmandal

According to the erlang docs, :epath means: “No such file or directory, or directory already exists, or permission denied.”

The error codes are listed at the bottom of this page: ftp

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
mnkhod
So i have been using ash framework for a while and i love it. However currently the issue im having with ash framework is the error handl...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews