11 August 2014

Simplest Way To Copy Any File From Your Computer Going To FTP Server in C#

protected void btnUpload_Click(object sender, EventArgs e)
    {
        FtpUpload("ftp://100.89.90.23", "myUserName", "myPassword", @"C:\ForUpload\myFile.txt");
    }

    private static void FtpUpload(string ftpServer, string userName, string passWord, string fileName)
    {
        using (var client = new WebClient())
        {
            client.Credentials = new NetworkCredential(userName, passWord);
            client.UploadFile(ftpServer + "/" + new FileInfo(fileName).Name, "STOR", fileName);
        }
    }

No comments:

Post a Comment