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:
- To Upload Files
- To Download Files:
- <code>
- <div style="overflow-x: scroll;">
- <div style="width: 1324px;">
- 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);
- }
- </div>
- </div>
- </code>
- <code>
- <div style="overflow-x: scroll;">
- <div style="width: 1324px;">
- if (Fileupload1.HasFile)
- {
- FTPclient ftPclient = new FTPclient("XXX.XXX.X.XX", "xx-xx", "xx-xx");
- ftPclient.Upload(fu_FtFile.FileContent, fu_FtFile.FileName);
- }
- </div>
- </div>
- </code>
- <code>
- <div style="overflow-x: scroll;">
- <div style="width: 1324px;">
- 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();
- </div>
- </div>
- </code>