Upload and Download a File to Ftp server through FTPClient Using C#


Today i want to discuss an article to upload a file through Ftp Client in C# which is an another Alternative to fileupload Control and WebClient Class. How it works i will illustrate with Code snippets.

Today i want to discuss an article to upload a file through Ftp Client in C# which is an another Alternative to fileupload Control and WebClient Class. How it works i will illustrate with Code snippets.

Some times we are given a task to move the Files from one Location to another Location with in Local Computer or Remote Computer and Many Programmers ask in Forum discussions how to relocate the Files from one Computer to another Computer or with in the Local computer. There are two ways to do it

1) using WebClient.UPloadFile ---- as discussed in Previous Article

2) Another is FtpClient .


How to work with this Ftp Client




In FTPCLIENT CLASS will be in System.Net as like WebClient

In FtpClient class Upload is the Method in C# that uploads the File in ftpserver....



First create an instance of ftpClient and call the Parameterised Constructor

FtpClient ftpclnt = new FtpClient("ftp://serevername",username, password )
ftpClnt.Upload(path of the Image/filename)
ftp.Close();



You can get all files in the Directory with this Piece of Code



FtpDirectory ftpdirect = myFtp.GetDirectory("/pub");





You can Use like this

Foreach( FTPfileinfo ftp in myFtpGetDirectory("/bin").GetFiles)
{
myftp.Download("file","location of the file")
}


Article by srirama
A Good advice from parent to a Child , Master to a Student , Scholar to an Ignorant is like a doctor prescribed pill it is bitter to take but when they take it will do all good for them --- Bhushan

Follow srirama or read 74 articles authored by srirama

Comments



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: