Net::FTP and UTF-8 encoding

Hey there,

I have a list of files with utf-8 characters in the name. Net::FTP
handles
them well, the content is just as I expected. But the problem comes with
the filename I expect on the server side. When I expect it to be
“somefile__.sample” it will upload as “somefile_©_.sample”.

I made some example code so you can duplicate it:
https://gist.github.com/3949372. The catch is that you need an FTP
account
to try it (line 51, 52). This will create a file with an special utf8
char
in /tmp and attempt to upload it.

I followed with debugger through the logic on Net::Ftp.put and found out
that the @socket.write method is responsible for this (@socket is a
TCPSocket object). So I’ve tried overloading the methods putfile and
storbinary from Net::FTP, setting @sock.set_encoding(‘utf-8’) to set the
default_external encoding, but to no avail. My filenames still appear
with
the wrong encoding on the FTP server.

Any suggestions?

PS.

  • I’m using ruby-1.9.3-p194
  • I’ve tried in clients such as Mac’s transmit and it works as expected,
    the special chars are respected.

Is the system encoding the same on your computer and the server? How
are you viewing the names on the server?

– Matma R.

mmm I was looking at the names just with transmit.app, but now that you
mention it, it seems to be fine looking at them with the ftp command.

Comparison of a file uploaded with transmit and net::ftp :

ftp command: http://cl.ly/image/1c3J3j2v2O03
transmit.app: http://cl.ly/image/39242U1v0I36

El jueves 25 de octubre de 2012 a las 11:23, Bartosz Dziewoński
escribió:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs