Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftp url for file names that contain spaces

Status
Not open for further replies.

awingnut

Programmer
Feb 24, 2003
759
US
I am having a problem with my FTP URLs because (I think) some of the file names contain spaces. The URLs without spaces seem to work fine.

For example the following does not work:
Code:
<a href=&quot;ftp://ftphost.somedomain.com/download directory/some file.zip&quot;>
What is the proper format for FTP URLs when target files and/or directories contain spaces so that FTP servers will recognize them. Thanks.
 
If you want to put a space in any filename it is common practice to use an underscore character ie

this_is_the_file.zip

Also remember to save the file in the same manner and on most systems filenames are case sensitive so
thisfile.zip is different to ThisFile.zip

hope this helps
regards
Ian

Infinity exists! - I just haven't worked out a way to get there yet.

| |
 
Thanks for the reply but I don't think I understand what you are saying. Are you saying the underscore will be interpreted as a space by the ftp server? What happens to filenames that actually contain and underscore?

I hope you are not asking me to rename files overwhich I have no control.
 
The way to put spaces into urls is this:


the 20 in between the %'s is the hex representation of 32, the decimal value of a space in ascii.

If you're using javascript you can convert spaces (or other special characters) to their proper url representations with the escape() method. You can convert back to their proper representations (from the %20% format) with unescape()

Hope that helps.
 
Thanks again but no, that didn't work.

The URL generated was:
Code:
ftp://ftphost.somedomain.com/download %directory/some %file.zip

I don't think the second '%' is valid but even removing it the '%20' still is a space in the final result.

This URL is generated using the PHP 'echo' function. If your objective is to have the actual string '%20' as part of the URL I cannot come up with a syntax to make that happen. If I use %%20 the resulting string is '% '.
 
You should be able to replace space characters with a plus (
Code:
+
) sign. Either way, a fairly quick fix should be using PHP's urlencode function, as described here:


If the echo command replaces the plus signs with spaces and it still doesn't work for you, then is there any other way to write something out besides echo?
 
Oh, and the previous answer for encoding spaces was mostly correct (in general, I know it didn't work for you), but you only need the leading percent sign (a space is
Code:
%20
).
 
Well, it is one of those days. This was a red herring. There was actually another problem that was causing the symptom which I mis-diagnosed. Boy, do I feel dumb. Sorry. :-(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top