Uploading File from Client to Server
-
Hello Experts, I would like ask how I will alow my client(the one browsing the internet) to upload the file into my web server. I set up my web application using the abyss web server so that I can host the website to my local machine, and for the FTP I use filezilla. Below here is my code but it's only working in my local machine.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Net;
using System.Web.UI.WebControls;namespace ftpPractice
{
public partial class _Default : System.Web.UI.Page
{protected void Page\_Load(object sender, EventArgs e) { } public void uploadFileUsingFTP(String CompleteFTPPath, String CompleteLocalPat) { try { //Create a FTP Request Object and Specfiy a Complete Path FtpWebRequest reqObj = WebRequest.Create(CompleteFTPPath) as FtpWebRequest; //Call A FileUpload Method of FTP Request Object reqObj.Method = WebRequestMethods.Ftp.UploadFile; //If you want to access Resourse Protected You need to give User Name and PWD reqObj.Credentials = new NetworkCredential("Akosidan", "newbie"); //File Stream obj read the file from local drive FileStream streamObj = File.OpenRead(CompleteLocalPat); //Store File in Buffer byte\[\] buffer = new byte\[streamObj.Length\]; // Read File from Buffer streamObj.Read(buffer, 0, buffer.Length); //Close FileStream Object Set its Value to nothing streamObj.Close(); streamObj = null; //Upload File to ftp://localHost/ set its object to nothing reqObj.GetRequestStream().Write(buffer, 0, buffer.Length); reqObj = null; lblMessage.Text= "File Uploaded Successfully :)"; } catch (Exception error) { Response.Write(error.ToString()); } //fs.Close(); //Stream ftpstream = ftp.GetRequestStream(); //ftpstream.Write(buffer, 0, buffer.Length); //ftpstream.Close(); } protected void cmdUpload\_Click(object sender, EventArgs e) { uploadFileUsingFTP("ftp://localhos
-
Hello Experts, I would like ask how I will alow my client(the one browsing the internet) to upload the file into my web server. I set up my web application using the abyss web server so that I can host the website to my local machine, and for the FTP I use filezilla. Below here is my code but it's only working in my local machine.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Net;
using System.Web.UI.WebControls;namespace ftpPractice
{
public partial class _Default : System.Web.UI.Page
{protected void Page\_Load(object sender, EventArgs e) { } public void uploadFileUsingFTP(String CompleteFTPPath, String CompleteLocalPat) { try { //Create a FTP Request Object and Specfiy a Complete Path FtpWebRequest reqObj = WebRequest.Create(CompleteFTPPath) as FtpWebRequest; //Call A FileUpload Method of FTP Request Object reqObj.Method = WebRequestMethods.Ftp.UploadFile; //If you want to access Resourse Protected You need to give User Name and PWD reqObj.Credentials = new NetworkCredential("Akosidan", "newbie"); //File Stream obj read the file from local drive FileStream streamObj = File.OpenRead(CompleteLocalPat); //Store File in Buffer byte\[\] buffer = new byte\[streamObj.Length\]; // Read File from Buffer streamObj.Read(buffer, 0, buffer.Length); //Close FileStream Object Set its Value to nothing streamObj.Close(); streamObj = null; //Upload File to ftp://localHost/ set its object to nothing reqObj.GetRequestStream().Write(buffer, 0, buffer.Length); reqObj = null; lblMessage.Text= "File Uploaded Successfully :)"; } catch (Exception error) { Response.Write(error.ToString()); } //fs.Close(); //Stream ftpstream = ftp.GetRequestStream(); //ftpstream.Write(buffer, 0, buffer.Length); //ftpstream.Close(); } protected void cmdUpload\_Click(object sender, EventArgs e) { uploadFileUsingFTP("ftp://localhos
-
Hello, Thanks for the link. Now I don't need anymore 3rd party ftp server just to transfer file :) Thanks again, DAN