protected void LinkButton1_Click(object sender, EventArgs e) { string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName); string ftpServerIP = "*"; string ftpUserName = "*"; string ftpPassword = "*"; FileInfo objFile = new FileInfo(filename); FtpWebRequest objFTPRequest; objFTPRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + "/" + objFile.Name)); objFTPRequest.Credentials = new NetworkCredential(ftpUserName, ftpPassword); objFTPRequest.KeepAlive = false; objFTPRequest.UseBinary = true; objFTPRequest.ContentLength = objFile.Length; objFTPRequest.Method = WebRequestMethods.Ftp.UploadFile; int intBufferLength = 16 * 1024; byte[] objBuffer = new byte[intBufferLength]; FileStream objFileStream = objFile.OpenRead(); try { Stream objStream = objFTPRequest.GetRequestStream(); int len = 0; while ((len = objFileStream.Read(objBuffer, 0, intBufferLength)) != 0) { objStream.Write(objBuffer, 0, len); } objStream.Close(); objFileStream.Close(); Console.Write("File upload success..."); } catch (Exception ex) { throw ex; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)