Click here to Skip to main content
15,868,146 members
Articles / Web Development / ASP.NET
Article

FTP Operation in a simple way...

Rate me:
Please Sign up or sign in to vote.
2.31/5 (11 votes)
15 Mar 2007 40.4K   28   7
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


Written By
Software Developer
India India
Chirag Patel, a Programmer Analyst in a well known IT company working on .NET Technologies since last 2 years. He is interested in Pure business logic and fuzzy logic. his area of interest is in C#.NET, VB.NET and MSSQL 2005.

catch me on: http://groups.google.com/group/codewar

Comments and Discussions

 
Generalftp and progress bar Pin
SuperBlois18-Mar-08 7:05
SuperBlois18-Mar-08 7:05 
GeneralRe: ftp and progress bar Pin
JustChiragPatel18-Mar-08 18:01
JustChiragPatel18-Mar-08 18:01 
QuestionUpload files when behind a proxy Pin
Shinuda17-Oct-07 21:08
Shinuda17-Oct-07 21:08 
Questionerror while downloading file from ftp Pin
ProsGIS30-Aug-07 4:23
ProsGIS30-Aug-07 4:23 
GeneralInternal Server Error Pin
Fact Pandit14-May-07 16:37
Fact Pandit14-May-07 16:37 
GeneralRe: Internal Server Error Pin
JustChiragPatel20-May-07 20:06
JustChiragPatel20-May-07 20:06 
GeneralRe: Internal Server Error Pin
Fact Pandit13-Jun-07 10:40
Fact Pandit13-Jun-07 10:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.