Cybercrux

Everything is achievable through technology

FTP Download

}

/// <summary>
/// Getting the FTP Class
/// </summary>
public FTPHelper.FTPConnection FTP
{
//Setting viewstate
set
{
ViewState[“FTP”] = value;
}
get
{
return ViewState[“FTP”] == null ? null : (FTPHelper.FTPConnection)ViewState[“FTP”];
}
}

/// <summary>
/// Connecting to FTP
/// </summary>
public void ConnectToFtp()
{
Dictionary<string, string> Files = new Dictionary<string, string>();
//Logging in to FTP server for getting FTP access
FTP = new FTPHelper.FTPConnection(“ftpurl”, “nikhil”, “pass”);
}
/// <summary>
/// Download from FTP url
/// </summary>
/// <param name=”frl”>The FTP URL</param>
protected void DownloadFtp(string frl)
{
try
{
byte[] _downFile = FTP.DownloadFileFromFtp(frl);
string _fname = frl;

//Taking Correct name of the file to be downloaded

string[] sss = _fname.Split(‘.’);
string[] sfname = sss[sss.Length – 2].Split(‘/’);
string ssfname = sss[sss.Length – 2];
Response.ContentType = “application/” + sss[sss.Length – 1];
if (ssfname.IndexOf(“/”) > 0)
{
Response.AddHeader(“Content-disposition”, “attachment; filename=” + sfname[sfname.Length – 1] + “.” + sss[sss.Length – 1]);
}
else
{
Response.AddHeader(“Content-disposition”, “attachment; filename=” + ssfname + “.” + sss[sss.Length – 1]);
}
Response.OutputStream.Write(_downFile, 0, _downFile.Length);
Response.End();
}
catch (Exception ex)
{
}
}

/// <summary>
/// Download Common Button Function
/// </summary>
/// <param name=”sender”></param>
/// <param name=”e”></param>
protected void btnDownload_Command(object sender, CommandEventArgs e)
{
string argurl = e.CommandArgument.ToString();

#region
if (argurl == “fullsetup”)
{
DownloadFtp(“ftp.cybercrux.in/file.exe”);
}
#endregion

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s