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); }
<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>
  1. <code>
  2. <div style="overflow-x: scroll;">
  3. <div style="width: 1324px;">
  4. FTPclient ftPclient = new FTPclient("XXX.XXX.X.XX", "xx-xx", "xx-xx");
  5. foreach (FTPfileInfo ky in ftPclient.ListDirectoryDetail(""))
  6. {
  7. TreeNode trParent = new TreeNode();
  8. trParent.Text = ky.Filename;
  9. trParent.Value = ky.FullName;
  10. trVFiles.Nodes.Add(trParent);
  11. }
  12. </div>
  13. </div>
  14. </code>
<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>
- 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); }
<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>
  1. <code>
  2. <div style="overflow-x: scroll;">
  3. <div style="width: 1324px;">
  4. if (Fileupload1.HasFile)
  5. {
  6. FTPclient ftPclient = new FTPclient("XXX.XXX.X.XX", "xx-xx", "xx-xx");
  7. ftPclient.Upload(fu_FtFile.FileContent, fu_FtFile.FileName);
  8. }
  9. </div>
  10. </div>
  11. </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>
- 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();
<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>
  1. <code>
  2. <div style="overflow-x: scroll;">
  3. <div style="width: 1324px;">
  4. FTPclient ftPclient = new FTPclient("XXX.XXX.X.XX", "xx-xx", "xx-xx");
  5. byte[] _downFile = ftPclient.Download(e.CommandArgument.ToString());
  6. string _fname = e.CommandArgument.ToString();
  7. Response.ContentType = "application/" + _fname.Split('.')[1];
  8. Response.AddHeader("Content-disposition", "attachment; filename=" + _fname);
  9. Response.OutputStream.Write(_downFile, 0, _downFile.Length);
  10. Response.End();
  11. </div>
  12. </div>
  13. </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>

Popular posts from this blog

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

C# Crop white space from around the image

The specified version string contains wildcards, which are not compatible with determinism.