Critical Developers

Programmers Knowledge Base

FTP File Upload from aspx page

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Upload("ftp://ftp.domain.com", "testuser", "testpwd", @"C:\abc.txt");
                    }
    }

    public void Upload(string ftpServer, string userName, string password, string filename)
    {
        using (System.Net.WebClient client = new System.Net.WebClient())
        {
            try
            {
                   client.Credentials = new System.Net.NetworkCredential(userName, password);
                   client.UploadFile(ftpServer + "/" + new FileInfo(filename).Name, "STOR", filename);              
            }
            catch (Exception ex)
            {

            }
        }
    }
}

Client detection from server side

Client detection from server side

string client_ip = System.Web.HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"];
string client_os = Request.Browser.Platform.ToString();
string os_ver = System.Environment.OSVersion.ToString();
string client_browser = Request.Browser.Browser.ToString() + " " + Request.Browser.Version.ToString();