Control Panel
Forum
Hosting Help
ASP.NET 3.5 & SQL 2008 Web Hosting
Resources
Login
Members
Shared Hosting
|
New Features
|
Advertise
|
Tutorials
|
Silverlight Tutorials
|
Product Reviews in India
|
Free aptitude test questions
|
TATA Nano Car reviews
Total
members
:
88776
Average new registrations per day (in last 7 days):
89
New Registration:
Open
Register Now
Home
»
Resources
»
Simple FTP Client
ASP.NET
ADO.NET
Web Services
Remoting
Visual Studio 2005
Error Bank
Interview Questions
Tips & Tricks
XML
HTML
Jscript/Javascript
IIS
Windows
General
Submit Resource or code snippet
... and get
surprise gifts
Win Digital camera, ASP.NET Books, Free softwares!!
Simple FTP Client
21 Apr, 2008
Author:
Jeff123
Summary
FTP Sample
The System.Net namespace adds full support for the FTP protocol, making it easy to create full featured FTP clients in .NET.
.NET Classes used :
using System;
using System.Text;
using System.IO;
using System.Net;
using System;
using System.Text;
using System.IO;
using System.Net;
namespace FTPSample
{
class SimpleFTPClient
{
public FtpStatusCode Download(string destinationFile, Uri downloadUri)
{
try
{
// Check if the URI is and FTP site
if (downloadUri.Scheme != Uri.UriSchemeFtp)
{
throw new ArgumentException("URI is not an FTp site");
}
// Set up the request
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(downloadUri);
// use the provided credentials
if (this._isAnonymousUser == false)
{
ftpRequest.Credentials = new NetworkCredential(this._userName, this._password);
}
// Download a file. Look at the other methods to see all of the potential FTP features
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
// get the response object
FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
Stream stream = null;
StreamReader reader = null;
StreamWriter writer = null;
// get the file as a stream from the response object and write it as
// a file stream to the local PC
try
{
stream = ftpResponse.GetResponseStream();
reader = new StreamReader(stream, Encoding.UTF8);
writer = new StreamWriter(destinationFile, false);
writer.Write(reader.ReadToEnd());
return ftpResponse.StatusCode;
}
finally
{
// Allways close all streams
stream.Close();
reader.Close();
writer.Close();
}
}
catch (Exception ex)
{
throw ex;
}
}
public string UserName
{
get { return this._userName; }
set { this._userName = value; }
}
public string Password
{
get { return this._password; }
set { this._password = value; }
}
public bool IsAnonymousUser
{
get { return this._isAnonymousUser; }
set { this._isAnonymousUser = value; }
}
private string _userName;
private string _password;
private bool _isAnonymousUser;
}
}
Feedbacks about this page from members:
- No Feedbacks yet !! -
Submit Feedback
View All Feedbacks
Partners
Privacy Policy
Terms of use
Contact Us
SpiderWorks Technologies.
All Rights Reserved.