Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trying to FTP a file with a special character

Tags:

c#

ftp

I have the code:

FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(url);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.UseBinary = true;   // Binary mode when downloading
request.Credentials = new NetworkCredential(user, password);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();

I always get the error: "The requested URI is invalid for this FTP command".

The problem is the url contains a "#". Since I can't stop people from creating that type of file, is there a way I can escape special characters and still process the file?

like image 272
Dez Hood Avatar asked Jun 14 '11 21:06

Dez Hood


2 Answers

Do a string replace with "#" ->"%23"
URL encodings shouldn't contain a hash because:

Some characters present the possibility of being misunderstood within URLs for various reasons. These characters should also always be encoded.

like image 167
Jean-Bernard Pellerin Avatar answered Sep 26 '22 20:09

Jean-Bernard Pellerin


You can use HttpUtility.UrlEncode to encode the special characters.

like image 21
satnhak Avatar answered Sep 22 '22 20:09

satnhak