Programming doubt Can anyone explain me how the code functions it is about downloading the file using FTP

Jun 3 2008 5:42 PM

System.Net.FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftp.oreilly.com/pub/examples/csharpckbk/CsharpCookbook.Zip");

request.Credentials = new NetWorkCredential("anonymous", "[email protected]");

using (FtpWebresponse response = (Ftpwebresponse)request.GetResponse())

{

Stream data = response.GetResponseStream();

string targetPath = "CSharpCookbook.Zip";

if (File.Exists(targetPath))

File.Delete(targetPath);

byte[] byteBuffer = new byte[4096];

using (FileStream output = new FileStream(targetPath, FileMode.CreateNew))

{

int bytesRead = 0;

do

{

bytesRead = data.Read(byteBuffer, 0, byteBuffer.Length);

if (bytesRead > 0)

{

output.Write(byteBuffer, 0, bytesRead);

}

}

while (bytesRead > 0);

}