FTP upload, download, delete ,get files asp.net
you first need to download
FtpClient.cs
from
here
once you add this file to your project you can upload - download - delete and get files from FTP servers
- To get all files from ftp:
FTPclient ftPclient = new FTPclient("XXX.XXX.X.XX", "xx-xx", "xx-xx");
foreach (FTPfileInfo ky in ftPclient.ListDirectoryDetail(""))
{
TreeNode trParent = new TreeNode();
trParent.Text = ky.Filename;
trParent.Value = ky.FullName;
trVFiles.Nodes.Add(trParent);
}
- To Upload Files
if (Fileupload1.HasFile)
{
FTPclient ftPclient = new FTPclient("XXX.XXX.X.XX", "xx-xx", "xx-xx");
ftPclient.Upload(fu_FtFile.FileContent, fu_FtFile.FileName);
}
- To Download Files:
FTPclient ftPclient = new FTPclient("XXX.XXX.X.XX", "xx-xx", "xx-xx");
byte[] _downFile = ftPclient.Download(e.CommandArgument.ToString());
string _fname = e.CommandArgument.ToString();
Response.ContentType = "application/" + _fname.Split('.')[1];
Response.AddHeader("Content-disposition", "attachment; filename=" + _fname);
Response.OutputStream.Write(_downFile, 0, _downFile.Length);
Response.End();
Comments
Post a Comment