This blog is about the dotnet.all types of codes,news about dotnet including asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.ncluding asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.asp.net programming,dot net programming,dotnet programs,dotnet source code,source code.

Free Hosting

Free Hosting

Friday, May 16, 2008

C-sharp Code to Upload a file through ftp

Here I am giving the code to access ftp server thruogh your .net applcation. The code works on both windows as well as web. You can upload a file through ftp and make your own ftp client by researching more on this top.

System.Net.FtpWebRequest ftpClient=System.Net.FtpWebRequest.Create("ftp://Yoursite.com/yourdirectory/"+"Filename");
ftpClient.Credentials = new System.Net.NetworkCredential("loginname", "password");
ftpClient.Method=System.Net.WebRequestMethods.Ftp.UploadFile;
ftpClient.UseBinary=true;
System.IO.FileInfo fi= new System.IO.FileInfo("Local FilePath to be Uploaded");
ftpClient.ContentLength=fi.Length;
int bufferSize=2048;
byte[] content= new byte[bufferSize-1];
int dataread;
System.IO.FileStream fs=fi.OpenRead();
try
{
}
catch (Exception ex)
{
System.IO.Stream rs=ftpClient.GetRequestStream();
do{
dataread=fs.Read(content,0,bufferSize);
rs.Write(content,0,dataread);
}while(dataread<bufferSize);
}


finally
{
fs.Close();

0 comments:

dotnet(.Net) Project Source code Downloads and Tutorials

Email Subscrption



Enter your email address:

Delivered by FeedBurner

Feedburner Count

Unique Visitor

Design by araba-cı | MoneyGenerator Blogger Template by GosuBlogger