Click here to Skip to main content
15,887,871 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Please tell me how to upload a XML file using FTP in c#? Im currently using FtpWebRequest method and its giving me The remote server returned an error: (553) File name not allowed. in Stream reqStream = request.GetRequestStream(); line

my code is

//Create FTP request
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://www.itsthe1.com/profiles/nuwan/sample.txt");

request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(Username, Password);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;

//Load the file
FileStream stream = File.OpenRead(@"C:\sample.txt");
byte[] buffer = new byte[stream.Length];

stream.Read(buffer, 0, buffer.Length);
stream.Close();

//Upload file
Stream reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
Posted
Comments
Sergey Alexandrovich Kryukov 14-Feb-12 12:57pm    
Look right. Is this URL valid? Did you try to upload a file using available client? Did it work?
--SA

1 solution

Dear,

You are using "Sample.txt" at the end try using "Sample.xml"

thanks,
Aamer.
 
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