Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

FTP Operation in a simple way...

0.00/5 (No votes)
15 Mar 2007 2  
code FTP Operation in just 4-5 lines...

Introduction

This article will enable you to write FTP operation in just 5 minutes...

We know that FTP same as direcotry structure which we have on our system, but the difference is that FTP directory is located at some other place.

So when you upload afile you are transfering one file from one place to another, just like in Unix programming, if we want to copy one file from one place to another we

Background

for more Information about Class used in this article Please refer MSDN...

Using the code

you just have to copy and paste this code into your code and that will able to upload or download files from the FTP specified by you...
:

//

// Just Rename File name and FTP location that you want to upload or download.

// 

//Generate the File name which you want to upload on the FTP... 

string ftpFilename = ftpServer + FileName;

//Create a Object of class WebClient.. 

WebClient client = new WebClient();
//Give the Credincials which will help you to enter into the FTP..


client.Credentials = new NetworkCredential(loginName, ftpPwd);

//Now use .UploadFile Method of WebClient Object to upload the file,

this method will return response from the FTP server which you can use as, 
result of FTP operation.. 

responseArray = client.UploadFile(ftpFilename, filetobeUploaded); 
 
//here you have to pass full path of FTP directory with filename included as

 ftpFilename, like if you want to upload file to ftp://simpleftp.com then

use this kind of structure..
ftpFilename = "ftp://simpleftp.com/test.txt";
//and in the 'filetobeUploaded' give name of your file to be uploaded..

 
//same way you can download the file by using .downloadfile method of the 

Webclient class Object.
 
//so enjoy the FTP operation in just 5 minutes..


Points of Interest

I like to Share my knowledge with guys like you, because i am also one of you, that if i dont know anything then i come to you...so keep exchange of knowledge...

History

If i find any shorter method of FTP then defenetly i will add that in this article...

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here