1

I am not sure what I am missing, but I have FTP connection that I have to download the contents (if any). I run the following code:

    connection.nlst('*.*').each do |entry|
      connection.getbinaryfile(entry, downloaded_file_path)
    end

The problem is when the folder is empty, it raises Net::FTPPermError Exception: 550 *: No such file or directory.. But when the folder has content, it works just fine.

I am not sure what to try, but here is some of the output to show that the connection is working:

> connection.list
["total 0"]

> connection.pwd
"/ftp/pub/Responses"

> connection.nlst
Net::FTPPermError Exception: 550 *: No such file or directory.

I would expect nlst to return an empty array, not raise an exception?

Tom Rossi
  • 11,604
  • 5
  • 65
  • 96
  • `nlst` is raising an exception because the ftp server return 550, which could be down to how that particular ftp server is implemented. – Frederick Cheung Mar 15 '15 at 21:36
  • is there a way I can determine if it is empty before nlst? – Tom Rossi Mar 15 '15 at 22:41
  • **"If the file is a regular file, the server provides information about that file, in the same format as a single directory entry. However, if the file is a directory, most servers will provide the contents of the directory, rather than information about the directory. If the client says NLST x, for example, and the response is x\015\012, then x could be a directory containing one file x, or it could be a regular file; the client can't tell. This inconsistency makes LIST and NLST parameters useless for most applications."** Seems difficult References: [http://cr.yp.to/ftp/list.html] – engineersmnky Mar 16 '15 at 13:32
  • You could just handle the error using a rescue block but that would be my only real useful suggestion. – engineersmnky Mar 16 '15 at 13:33

0 Answers0