FTP filename escaping

A

Almad

Hello,

I feel ashamed, but my google-fu betrayed me again.

How do I escape filenames when using ftplib? I'd like to download it
and upload on ftp again...
toDown = self.ftpMaster.nlst()
for fileDown in toDown:
f = tmpfile()
# download
self.ftpMaster.retrbinary(''.join(['RETR ', fileDown]),
f.write)
f.seek(0)
self.ftpMirror.storbinary(''.join(["STOR ", fileDown]), f,
1024)
f.close()

Problem is when fileDown contains special characters / spaces and so
on. I hoped for some ftplib.quote(), urllib.quote() or quote_plus() is
not functional either.

Is there such a function in stdlib or do I have to read through
specification and write it?

Thank You,

Almad
 
A

Almad

OK, after some investigation...problem is in non-latin characters in
filenames on ftp.

Yes, users should be killed for this, but I would like to handle it
somehow...

I can't figure out how it's handled by protocol, ftplib seems to just
strip those characters...

Thank You,

Almad
 
S

Serge Orlov

Almad said:
OK, after some investigation...problem is in non-latin characters in
filenames on ftp.

Yes, users should be killed for this,

It's futile, users will always find a way to crash you program :) And
you can't kill them all, there are too many of them.
but I would like to handle it
somehow...

It depends on what you're actually doing. Did you write the ftp server?
Or do you have any information about server (OS etc...)? Is your client
the only client who can upload? Do you care how file names actually
look interally in the server?
I can't figure out how it's handled by protocol, ftplib seems to just
strip those characters...

I believe filename == sequence of bytes terminated by newline byte. I
doubt ftplib strips bytes over 127. Even if it does, copy it to your
private module collection as ftplibng.py, fix it and import ftplibng as
ftplib
 
E

Edward Elliott

Serge said:
It's futile, users will always find a way to crash you program :) And
you can't kill them all, there are too many of them.

Yes but you can take their toys away. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top