Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i upload a file to ftp i am getting an error like this can any one please help me
C#
FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("file location"));
                //set the method to Upload, since we're uploading a file
                ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
                //pass in our login credentials
                ftpRequest.Credentials = new NetworkCredential("username", "password");
                //don't use passive mode
                ftpRequest.UsePassive = true;
                //unless we're uploading a file like an image
                //we need to set this to false as we're not uploading
                //binary data
                ftpRequest.UseBinary = true;
                //set KeepAlive to false
                ftpRequest.KeepAlive = false;

                //now create a new FileStream, then open the file we're uploading
                //this allows us to get the size of the file for our buffer
                FileStream stream = File.OpenRead("local file path");
                //create a byte[] array buffer the size of the file
                //we're uploading
                byte[] buffer = new byte[stream.Length];

                //read in our file into the FileStream
                stream.Read(buffer, 0, buffer.Length);
                //close the FileStream
                stream.Close();

                //create a new stream, this will be used to write to the
                //FTP server
                Stream requestStream1 = ftpRequest.GetRequestStream();
                //write the data to the FTP server
                requestStream.Write(buffer, 0, buffer.Length);
                //close the stream
                requestStream.Close();
Posted
Updated 1-Sep-12 0:43am
v2

1 solution

Here is a similar thread. Hope this helps
The requested URI is invalid for this FTP Command.[^]
 
Share this answer
 
Comments
siva575 1-Sep-12 6:37am    
thank you for the reply it not help full for me
siva575 1-Sep-12 6:41am    
i am getting an error over here


Stream requestStream1 = ftpRequest.GetRequestStream();

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