C# .NET - WebClient error
Asked By Ganesan BalaKrishnan
10-May-10 05:43 AM
I am using C#, ASP.net version 1.1. I have the following code using a webclient
in an attempt to ftp a file to my server.
System.Net.WebClient webClient = new System.Net.WebClient();
System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential("username","password");
webClient.Credentials = networkCredential;
webClient.UploadFile("ftp://michaelrparker.biz/PerlFiles/" + fi.Name.ToString(),fi.FullName);
I am getting an error that The URI prefix is not recognized.
How to resolve this error?
Phivos Stylianides replied to Ganesan BalaKrishnan
This error only appears in version 1.1. If you use the same code with a newer version you will see that the error is gone. If you have to use this framework version you should use Sockets to connect to the server, it involves more code but it will work.
Anand Malli replied to Ganesan BalaKrishnan
Hi Ganesan,
As fas .NET framework 1.1 is concern It's not able to identify FTP as valid protocol for WebClient class. So you can't use WebClient for uploading file on FTP, If your application is targeting framework ver 1.1 .
Options:
1) Upgrade your application to framework 2.0 (Recommended option).
2) Use conventional method from early C/C++ days, Create Socket for your FTP address & upload your file using Socket.
Let me know if you face any difficulties while implementation....:)

transfer folder from one ftp server to the other ftp server. . . . You can try using webclient class. . . WebClient wc = new WebClient(); wc.Credentials = new NetworkCredential ("username", "password"); wc.UploadFile(" ftp: / / 1.23.153.248 / ftp.bmp ", @"C: \ Documents and Settings Is your ftp public? if no you should define credentials like this wc.Credentials = new NetworkCredential ("username", "password"); before sending file, and try to remove d: from ftp path. ftp clients don't have to know where on server files should be saved. . . shortly try this WebClient wc = new WebClient(); wc.Credentials = new NetworkCredential ("username", "password"); wc.UploadFile("ftp: / / 1.23.153.248 / ftp.bmp
Download a file with credentials - username and password - in C# Use the System.Net.WebClient class to download a file with credentials. See the following example, WebClient downloadWC = new WebClient(); downloadWC.Credentials = new System.Net.NetworkCredential("egg", "kiosk"); byte[] buff = downloadWC.DownloadData("http: / / www.downloads.com / files / file.txt"); using (System following code snippet to download an image from an URL. Download a file using the WebClient class Use the WebClient class from System.Net namespace to download and save a file. Download a file with
C# webclient - access web through proxy server I am currently using C# and the webClient class to downloading and uploading images, data, see code below public BasicFTPClient(string theUser, string thePassword Path)); } public byte[] DownloadData(string path) { / / Get the object used to communicate with the server. WebClient request = new WebClient(); / / Logon to the server using username + password request.Credentials = new NetworkCredential(Username, Password); return request.DownloadData(BuildServerUri(path)); } / / / <summary> / / / This method downloads the FTP file specified encountering a network error. / / / < / summary> public void DownloadFile(string ftppath, string destfile) { / / Download the data WebClient request = new WebClient(); byte[] Data = DownloadData(ftppath); / / Save the data to disk FileStream fs = new FileStream(destfile, FileMode
WebClient Class: Gotchas and Basics Some basics of the useful WebClient class along with some things to watch out for. For Oscar Peterson , who died today. We Permanent Redirect response, suggesting that the client try again with the trailing slash. A .NET WebClient or WebRequest will respond just like a browser would - by re-requesting the resource with not have a proxy in use, you should set the Proxy property on all your WebClient and WebRequest objects to null. If you do not do this, you run the risk so: WebRequest.DefaultWebProxy = null; The above will apply for the lifetime of the application domain. WebClient Class WebClient is simply a wrapper over the WebRequest and WebResponse classes which can save a