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);
}