Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Uploading File from Client to Server

Uploading File from Client to Server

Scheduled Pinned Locked Moved C#
csharplinqdesignsysadminhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    akosidandan
    wrote on last edited by
    #1

    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
    
    N 1 Reply Last reply
    0
    • A akosidandan

      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
      
      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Uploading Files in ASP.NET 2.0[^]


      I know the language. I've read a book. - _Madmatt

      A 1 Reply Last reply
      0
      • N Not Active

        Uploading Files in ASP.NET 2.0[^]


        I know the language. I've read a book. - _Madmatt

        A Offline
        A Offline
        akosidandan
        wrote on last edited by
        #3

        Hello, Thanks for the link. Now I don't need anymore 3rd party ftp server just to transfer file :) Thanks again, DAN

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups