MATLAB: Do I get the error “Error downloading URL” when trying to open an FTP URL that needs a password in MATLAB 7.8 (R2009a)

MATLABurlencode

I am trying to read from an FTP server using the following code:
urlread(< 'ftp://username:mypass12{+[34@ftp.dummyserver.com/'>)
But I get the following error:
??? Error using ==> urlread
Error downloading URL. Your network connection may be down or your proxy settings improperly configured.

Best Answer

The problem is caused by using an opening square bracket "[" in the password. A closing square bracket "]" would lead to the same error. The ability to automatically encode usernames or passwords for servers is not available in MATLAB.
To work around this issue, you can use Java functionality to URL-encode the password (or the username if needed) as follows:
urlread(['ftp://username:' char(java.net.URLEncoder.encode('mypass12{+[34')) '@ftp.dummyserver.com/'])
Keep in mind that the format of the URL should be:
Do not encode the colon ":" between the username and the password.