Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the remote server returned an error(550 file unavailable).
as far as i am aware of # can be used in naming files then why do i get error to access files and folders that have # in their name?
get error here on getrequeststream();

What I have tried:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(string.Format("{0}/{1}", server, fileName)));
            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.Credentials = new NetworkCredential(userName, passowrd);
            Stream ftpStream = request.GetRequestStream();
Posted
Updated 19-Jul-19 5:57am
Comments
Member 12899279 19-Jul-19 6:13am    
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(string.Format("{0}/{1}", server, fileName)));
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(userName, passowrd);
Stream ftpStream = request.GetRequestStream();
FileStream fs = File.OpenRead(fullName);
byte[] buffer = new byte[1024];
double total = (double)fs.Length;
int byteRead = 0;
double read = 0;
do
{
if (!backgroundWorker1.CancellationPending)
{
byteRead = fs.Read(buffer, 0, 1024);
ftpStream.Write(buffer, 0, byteRead);
read += (double)byteRead;
double percentage = read / total * 100;
backgroundWorker1.ReportProgress((int)percentage);
}
}
while (byteRead != 0);
fs.Close();
ftpStream.Close();
Richard MacCutchan 19-Jul-19 6:44am    
Try it without the # character.
Member 12899279 19-Jul-19 6:57am    
offcourse i tried it for files and folder without # and that works fine but that's not the solution i have many folders and files which i want to use and have # in their name
Richard MacCutchan 19-Jul-19 8:06am    
Try using the control code # instead of the hash character. Although there may be some other reason why the server rejects it.
MadMyche 19-Jul-19 8:07am    
or %23

The most likely reason is that while the # may be valid in a filename, it is used as a delimiter in a URL.
Reference: https://www.ietf.org/rfc/rfc1738.txt[^]
RFC 1738, published December 1994
Unsafe:
Characters can be unsafe for a number of reasons.

The space character is unsafe because significant spaces may disappear and insignificant spaces may be introduced when URLs are transcribed or typeset or subjected to the treatment of word-processing programs.

The characters "<" and ">" are unsafe because they are used as the delimiters around URLs in free text; the quote mark (""") is used to delimit URLs in some systems.

The character "#" is unsafe and should always be encoded because it is used in World Wide Web and in other systems to delimit a URL from a
fragment/anchor identifier that might follow it.

The character "%" is unsafe because it is used for encodings of other characters.

Other characters are unsafe because gateways and other transport agents are known to sometimes modify such characters. These characters are "{", "}", "|", "\", "^", "~", "[", "]", and "`".
 
Share this answer
 
v2
Comments
Member 12899279 19-Jul-19 7:32am    
is there any way or anything that i should change in the above code to get it working because i need to use # in file and foldernames both so i cannot eliminate this
you said about encoding how should i encode it while uploading?
MadMyche 19-Jul-19 8:05am    
You would use the UrlEncode method to encode it.
I personally would change the naming conventions as retaining the special character can be troublesome for FTP clients.
You could also do a character replacement prior to upload and then "un-replace" on download.
Either way is a bandage for some "business requirement" that wants to do something that is not compliant with a standard that is 25 years old.
Member 12899279 19-Jul-19 10:27am    
character replacement would need extra coding..how to use urlEncode to rectify the issue?any eg?
MadMyche 19-Jul-19 11:07am    
Any bandage you apply to this is going to require coding and testing. Hit up google with "C# UrlEncode" to see plenty of examples
string nn = comboBox1.Text.ToString();
           string name2;
           if (nn.Contains("#"))
           {
                name2= nn.Replace("#", "%23");
           }
           else
           {
               name2=nn;
           }


got this as a temporary fix.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900