WebCLient

T

Thom Little

Is it possible to use WebClient.DownloadFile and WebClient.UploadFile to a
FTP server that requires a user name and password?

If yes, how is the authentication information passed to the server?

What was the source of your information?
 
N

.net noobie

http://www.dotgnu.org/pnetlib-doc/System/Net/WebRequest.html

using System;
using System.Net;

public class ftpWebRequest : WebRequest {
//implement ftp-specific protocol methods and properties
}

public class ftpCreator : IWebRequestCreate
{
public WebRequest Create(Uri uri)
{
return new ftpWebRequest();
}
}

public class RegisterPrefixExample
{

public static void Main()
{

ftpCreator creator = new ftpCreator();
WebRequest.RegisterPrefix("ftp://", creator);
WebRequest wr = WebRequest.Create("ftp://testFile");
Console.WriteLine(wr);
}
}
 
S

Steven Cheng[MSFT]

Thanks for netnoobie's input.

Hi Thom,

As for the WebClient class is using the WebRequest component internally, so
it can only access remote resources through the existing registred
WebRequest components. For .net 1.1, there is only Http/https based or
local File:// protocol based component avaliable. So we can not use the
WebClient class to access remote resource through FTP protocol. Also, in
..NET 2.0 there has provided FtpWebRequest and FtpWebResponse class as
build-in components which can help performing FTP resource accessing.

#FtpWebRequest Class
http://msdn2.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: WebCLient
| thread-index: AcXnK+cCEvfE4T5DRuSU78rr4/DguA==
| X-WBNR-Posting-Host: 202.172.113.6
| From: "=?Utf-8?B?Lm5ldCBub29iaWU=?=" <[email protected]>
| References: <[email protected]>
| Subject: RE: WebCLient
| Date: Fri, 11 Nov 2005 17:53:39 -0800
| Lines: 47
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:31101
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| http://www.dotgnu.org/pnetlib-doc/System/Net/WebRequest.html
|
| using System;
| using System.Net;
|
| public class ftpWebRequest : WebRequest {
| //implement ftp-specific protocol methods and properties
| }
|
| public class ftpCreator : IWebRequestCreate
| {
| public WebRequest Create(Uri uri)
| {
| return new ftpWebRequest();
| }
| }
|
| public class RegisterPrefixExample
| {
|
| public static void Main()
| {
|
| ftpCreator creator = new ftpCreator();
| WebRequest.RegisterPrefix("ftp://", creator);
| WebRequest wr = WebRequest.Create("ftp://testFile");
| Console.WriteLine(wr);
| }
| }
|
|
| "Thom Little" wrote:
|
| > Is it possible to use WebClient.DownloadFile and WebClient.UploadFile
to a
| > FTP server that requires a user name and password?
| >
| > If yes, how is the authentication information passed to the server?
| >
| > What was the source of your information?
| >
| > --
| > -- Thom Little -- www.tlanet.net -- Thom Little Associates, Ltd.
| > --
| >
| >
| >
| >
|
 
N

.net noobie

you can use webclient in 1.1 to do FTP

there is a class on MSDN that makes a FTPWebRequest

u need to use that class, or make yur own... but eaiser to use theres
 
T

Thom Little

Thank you everyone.

I was in a "blind spot" and just didn't see it. It is monumentally simple.

Download ...
using System.Net ;
WebClient wc = new WebClient( );
wc.Credentials = new NetworkCredential( "someaccount", "somepassword" );
wc.DownloadFile( "ftp://ftp.somedomain.tld/somefile.txt",
@"c:\temp\somefile.txt" );

Upload ...

Using System.Net ;
WebClient wc = new WebClient( );
wc.Credentials = new NetworkCredential( "someaccount", "somepassword" );
wc.UploadFile( "ftp://ftp.somedomain.tld/somefile.txt",
@"c:\temp\somefile.txt" );

-- Thom Little -- www.tlanet.net -- Thom Little Associates, Ltd.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top