Click here to Skip to main content
14,603,826 members
Rate this:
Please Sign up or sign in to vote.
See more:
hello can some one help me to upload a text file to ftp local host i have an error this is my code



string filename = Path.GetFileName("C:\\inetpub\\ftproot\\reg.txt");

               FtpWebRequest request = (FtpWebRequest)WebRequest.Create("127.0.0.1 + ftp/reg.txt");

               request.Method = WebRequestMethods.Ftp.UploadFile;

               request.Credentials = new NetworkCredential("username", "password");

               StreamReader sourceStream = new StreamReader("C:\\inetpub\\ftproot\\reg.txt");

               byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());

               request.ContentLength = fileContents.Length;

               Stream requestStream = request.GetRequestStream();

               requestStream.Write(fileContents, 0, fileContents.Length);

               FtpWebResponse response = (FtpWebResponse)request.GetResponse();

               response.Close();

               requestStream.Close();

               sourceStream.Close();
Posted
Comments
Member 11407981 2-Feb-15 12:09pm
   
here is the error Error:System.UriFormatException: Invalid URI: The format of the URI could not be determined. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at System.Uri..ctor(String uriString) at System.Net.WebRequest.Create(String requestUriString)

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

As the error message says, the parameter to WebRequest.Create needs to be a valid URI. The value you've passed in ("127.0.0.1 + ftp/reg.txt") is not a valid URI.

The URI should look something like:
"ftp://127.0.0.1/reg.txt"


However, this code doesn't make any sense. You're taking a file from the server, and trying to upload it via FTP to the same location on the same server!
   
Comments
   
5ed.
—SA

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100