Obscure problem

Ran into an annoying problem recently where an FTP account I was logging in with had a home directory of something like this:

/dir0/dir1/dir3/Home

To my dismay I needed to upload files to:

/dir0/belowHome/dir1/dir2

By default everything is a relative path to your home directory when you are moving around with FTP. My situation was I am pushing files using C# and no library, so I am making web requests to an FTP server. Therefore it is a very rigid interaction. If you can use a library then do so, but in my case I needed to avoid using a library.

I tried using relative paths by doing something like this:

/dir0/dir1/dir3/Home/../../../belowHome/dir1/dir2/

Ugly solution, but it is a relative path and unfortunately it didn’t work anyhow.

Obscure solution

I never would have guessed this solution and I did have to do a lot of searching until I found it. It works for now so I am using it.

In order to use absolute paths with FTP you need to start your path with “%2F” which is the URL Encoding for forward slash “/” I don’t think this is a coincidence.

Example:

%2Fdir0/belowHome/dir1/dir2

This resolves your problem of your home directory getting in the way of where you are trying to go. I would recommend only do this as necessary. This is not a hack, it is written directly in the ietf.org specification – link below.

Supporting links

Leave a Reply

Your email address will not be published. Required fields are marked *