Why can't Net::FTP connect to server?
Your code works fine for me. I suspect problem could be because of Net::FTP
connection mode, which is by default active. Try connecting using passive mode, following code sample -
ftp = Net::FTP.new(server)
ftp.passive = true
ftp.login user, password
files = ftp.chdir('mydirectory/')
files = ftp.list
puts "list out of directory:"
puts files
ftp.close
And if you're curious, following is the difference (from wikipedia) between active and passive modes.- In Active mode, the client creates a TCP control connection to the server and sends the server the client's IP address and an arbitrary client port number, and then waits until the server initiates the data connection over TCP to that client IP address and client port number. In situations where the client is behind a firewall and unable to accept incoming TCP connections, passive mode may be used.
- In Passive mode, the client uses the control connection to send a PASV command to the server and then receives a server IP address and server port number from the server which the client then uses to open a data connection from an arbitrary client port to the server IP address and server port number received.
Ruby Net::FTP - Downloading files from a server
The error message comes from the FTP server. The problem is that the FTP server cannot interpret these unicode filenames. Please check if UTF8 feature is enabled for the connection.
From an existing answer on stackoverflow:
It is not enough for you just to encode your string as UTF8 and send it as filename to FTP server. In the past all FTP servers understood ASCII only and nowadays to maintain backward compatibility - even if they are Unicode aware - when they start they treat all filenemes as ASCII too.
To make it all work you (your program) must first check what your server is capable of. Servers send their features after client connects - in your case you must check for FEAT UTF8. If your server sends that - it means it understands UTF8. Nevertheless - even if it understands it - you must tell it explicitly that from now on you will send your filenames UTF8 encoded and now it is the stuff that your program lacks (as your server supports utf8 as you've stated).
Your client must send to FTP server the following OPTS UTF8 ON. After sending that you may use UTF8 or speak UTF8-ish (so to speak) to your sever.
Read here for details Internationalization of the File Transfer Protocol
Sources:
https://stackoverflow.com/a/19903611/1305200
https://wiki.filezilla-project.org/Character_Encoding
Ruby FTP not working with IIS FTP server
I set passive to false and that solved my problem.
Related Topics
Rvm Can No Longer Install 1.8.7-P352 on MAC Os X Mountain Lion
How to Check If an Object Is Nil in a View in Ruby
How to Use C# Style Enumerations in Ruby
What Does Bundle Install -Without Production Do
Rails Routes: Nested, Member, Collection, Namespace, Scope and Customizable
Rails Gem Prawn, Image and Anchor
Can't Get Paypal Encrypted Website Payments to Work in Rails
Running Rails Console with Bundle Exec
Recommended Way to Generate a Presigned Url to S3 Bucket in Ruby
How to Mount a Sinatra Application Inside Another Sinatra App
Nomethoderror: Undefined Method 'On' for Main:Object
Gem Ransack Doesn't Return Any Results When Searched with Full Name
Is The Assignment Operator Really "Just" an Operator
Rake Cucumber and Rake Spec Always Use "Develop" Environment
Error Installing Rdoc Documentation: Incompatible Encoding Regexp Match
If I Have a Stripe Token from a Charge, How to Get Its Charge Id