Net::FTP and UTF-8 encoding

Hey there,

I have a list of files with utf-8 characters in the name. Net::FTP
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: The catch is that you need an FTP
to try it (line 51, 52). This will create a file with an special utf8
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
the wrong encoding on the FTP server.

Any suggestions?


  • 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, 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:

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

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