Click here to Skip to main content
Click here to Skip to main content

FTP Operation in a simple way...

, 15 Mar 2007
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

JustChiragPatel
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 PinmemberSuperBlois18-Mar-08 7:05 
GeneralRe: ftp and progress bar PinmemberJustChiragPatel18-Mar-08 18:01 
QuestionUpload files when behind a proxy PinmemberShinuda17-Oct-07 21:08 
Questionerror while downloading file from ftp PinmemberProsGIS30-Aug-07 4:23 
GeneralInternal Server Error PinmemberFact Pandit14-May-07 16:37 
GeneralRe: Internal Server Error PinmemberJustChiragPatel20-May-07 20:06 
GeneralRe: Internal Server Error PinmemberFact Pandit13-Jun-07 10:40 
Hi Chirag,
 
Sorry my late response and also thanks for your quick response. I found that the problem is happening becase I configured a directory for storing files in the Web Service web.config and that directory was not there and I was creating it neither. So that is what causing the problem.
 
Once again thank you very much for your response
 
Regards,
FP

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 15 Mar 2007
Article Copyright 2007 by JustChiragPatel
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid