protected void LinkButton1_Click(object sender, EventArgs e) { string filename = @"C:\inetpub\ftproot\RetailAgreement\abc.JPG"; string ftpServerIP = "192.148.10.10"; string ftpUserID = "username"; string ftpPassword = "password"; System.IO.FileInfo fileInf = new FileInfo(filename); string uri = "ftp://" + ftpServerIP + "/RetailAgreement/" + fileInf.Name; FtpWebRequest reqFTP; reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/RetailAgreement/" + fileInf.Name)); reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword); reqFTP.KeepAlive = false; reqFTP.Method = WebRequestMethods.Ftp.UploadFile; reqFTP.UseBinary = true; int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; FileStream fs = fileInf.OpenRead(); Stream strm = reqFTP.GetRequestStream(); // Read from the file stream 2kb at a time contentLen = fs.Read(buff, 0, buffLength); // Till Stream content ends while (contentLen != 0) { // Write Content from the file stream to the FTP Upload Stream strm.Write(buff, 0, contentLen); contentLen = fs.Read(buff, 0, buffLength); } // Close the file stream and the Request Stream strm.Close(); fs.Close(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)