Using Unicode file names with ftplib and encodings.idna as a workaround?

python at bdurham.com python at bdurham.com
Tue Jun 22 10:43:34 EDT 2010


Python 2.6.5 (Win32): Is there a work around for ftplib's (and
ftputil's) apparent inability to support Unicode file names?

I'm thinking that I might be able to use the encodings.idna as a
work around for this?

In other words, regardless of whether I'm getting or putting a
file to the server, I would encode the remote paths like so:

remotePath = encodings.idna.ToASCII( localPath )

I would then wrap the nlst command so that the list of returned
file names would have the following transformation applied to
each filename:

[ encodings.idna.ToUnicode( item ) for item in os.listdir('') ]

One downside is that processes on the server will also have to
wrap directory access with a similar transformation. This
wouldn't be too complicated for Python programs, but I'm not sure
how convenient this would be for our PHP and shell scripters.
(Just checked: There's a PEAR module for PHP4/5; oddly enough
nothing pops up for .NET IDNA libraries)

Another challenge: Which Python idna encoding technique to use? I
just started a thread that points out that
encodings.idna.ToASCII( fileName ) != fileName.encoding( 'idna'
).

Thoughts?

Malcolm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100622/55ad1259/attachment.html>


More information about the Python-list mailing list