Ruby NetSFTP: Strange error on attempting file download

349 Views Asked by At

I am experiencing a strange error using the NetSFTP gem in Ruby.

I am trying to download several status files from a remote STFP server.

My code looks like this:

sftp.dir.entries('/OUT/XMLACK').each do |entry|
  path_to_entry = "OUT/XMLACK/#{entry.name}"
  puts "Downloading #{path_to_entry}..."
  sftp.download!(path_to_entry, 'xml_ack_files/')
  puts "Downloaded #{path_to_entry} from server successfully"
end

When I run the above code, I always get the following error:

in `on_open': Net::SFTP::StatusException open OUT/XMLACK/test.P (4, "failure") (Net::SFTP::StatusException)

I can retrieve the files fine if I start an SFTP session in the Linux terminal, cd into the correct directory and issue a get command with the correct filename.

I suspect that the NetSFTP gem is trying to issue other commands than just a simple get which we don't have permissions for on the remote server.

How can I simply get the files? As a fallback, is it possible to issue a get command directly in the NetSFTP session - i.e. issue the get filename.P as a direct command to the SFTP server?

1

There are 1 best solutions below

0
On

I found the solution. I had to specify a local path AND filename to the download command, otherwise download errors out.