Thursday, December 20, 2007

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




//

// 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.

No comments: