Ran into an annoying problem recently where an FTP account I was logging in with had a home directory of something like this:
To my dismay I needed to upload files to:
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:
Ugly solution, but it is a relative path and unfortunately it didn’t work anyhow.
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.
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.
- Found the original answer here: https://stackoverflow.com/a/1174669/603807
- Specification here: https://tools.ietf.org/html/draft-casey-url-ftp-00 under section “2.5. Interpreting a FTP URL”.