Page view counter
HomeLearnVideosHow Do I: Use the FtpWebRequest Class to Create an FTP Connection to a FTP Server  

[How Do I:] Use the FtpWebRequest Class to Create an FTP Connection to a FTP Server

Please install Silverlight or click download to watch video locally.

In this video Chris Pels shows how to use the FtpWebRequest class to create an FTP connection and transfer a file. First, create a simple .aspx form to select a file to transfer to the FTP server. Next, see the essential methods and properties of the FtpWebRequest class that need to be configured in order to establish an FTP connection. Then, see how to get the local file contents so the file can be transferred using a StreamReader and a StreamWriter to write it to the FtpWebRequest. Finally, a FtpWebResponse is obtained to determine the outcome of the transfer. This approach can be used to programmatically transfer files for a web application.

Presented by Chris Pels

Duration: 21 minutes, 28 seconds

Date: 18 December 2008

Watch    Video   |   Download    Video   |   VB Code    C# Code

Video downloads: WMV  |  Zune  |  iPod  |  PSP  |  MPEG-4  |  3GP

Audio downloads: AAC  |  WMA  |  MPEG-4  |  MPEG-3  |  MPEG-2

Comments : 15

Leave a Comment

shaheenstar : On December 19, 2008 7:00 PM said:

Very helpful

agrawalbs : On December 20, 2008 1:06 AM said:

this is really very helpful, thanks

srameh : On December 21, 2008 3:50 PM said:

Very helpful. But if you can shorten these videos by having the <asp:Controls pre added to the page or by dragging and dropping them from the Toolbox instead of handcoding... would save some time. Over all it is awesome!

rami_nassar : On December 22, 2008 1:12 AM said:

as usual thanks chris

bluealigator : On December 26, 2008 11:25 AM said:

This video is excellent.

Now I will have to find out how to add an entire folder instead of a single file or files. Does anyone know how to add an entire folder instead of a single file or is it even possible?

iamrathan : On December 29, 2008 3:27 PM said:

chris thanks for your post,

can u suggest me ...how to download a folder from a ftp server? is this possible in web application?

is der any other techniques to handle this??

its really urgent for me....

Pushkar : On January 08, 2009 11:16 AM said:

Thanks for the nice one.We will appreciate if you elaborate more.Thanks again.

jasbits : On January 19, 2009 1:28 PM said:

Thanks,this was great

hieutdhn : On January 21, 2009 3:10 AM said:

thanks, this was helpful

georgemitchell : On January 29, 2009 11:35 AM said:

Never used ASP.NET so excuse the stupid question please.

Doesn't this example upload a file from the webserver to an FTP server?

I mean, what actually executes in the browser? I thought only javascript can run, but you're creating standard .NET WebRequest objects etc.

If I'm blind to the obvious please explain gently. After all, if I can't understand it there must be others too!

Thanks

CStroliaDavis : On February 05, 2009 2:02 PM said:

Hey georgemitchell,

I believe I can answer this question for you.

The asp:fileupload control, which outputs an <input type="file"> type control on the web page, handles the uploading of the file from the client machine to the web server.

When you submit the webform, it uploads the file to the web server, which appears as a byte array to ASP.net.

Most of what executes in the browser is already abstracted in the <input type="file"> control. No javascript is necessary (indeed, because of security, javascript usually can't do much with the file upload control at all), and the browser itself already handles the part of opening a file browser on the client when the browse button is pressed. It also handles wrapping the file up into the information that gets sent to the server when the form is submitted (note: I believe the method is required to be "post" for this, although I've never tried it another way).

In this example, that byte information is being put into a filestream and sent directly to the ftp server from the web server. (uploadFile control)

So, in answer to the question, yes, the example uploads the file from the web server to the ftp server but that is only after the client browser already uploaded the file to the web server.

Hope this helps

bbudz : On February 10, 2009 12:48 PM said:

Excellent video!  Very much appreciated.

bohunt : On February 13, 2009 5:44 PM said:

Useful, thanks.

barik.jyoti : On April 23, 2009 3:28 PM said:

This example was really helpful. Thanks Chris for that. It would be really helpful if any one can help me out with navigating and downloading from ftp using the same ftpwebrequest. Thanks in advance!!

kbaffoe : On May 09, 2009 12:59 AM said:

This video only works for me when I debug and test on the local machine. The local machine is also the ftp server. It does not actually work when I deploy and use from a remote machine. No errors are generated but it just doesn't transfer the files over

Leave a Comment

You must be logged in to leave a comment. Click here to log in.

Microsoft Communities