Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Upload > FTP with ASP.NET - get client upload path
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered FTP with ASP.NET - get client upload path

Feed from this thread
  • Tom avatar

    Posted on Mar 1, 2011 (permalink)

    I want to write a program that using FTP to upload files into server.

    But I cannot get the path from client to upload.

    How can I get client's path to upload files into my FTP server?

    Also, I would like to know what is the different between FileUpload1.FileName and FileUpload1.PostedFile.FileName ?

     

    Thanks a lot!

     

    my coding here...

        protected void Button1_Click(object sender, EventArgs e)

        {

            for (int p = 0; p < Request.Files.Count; p++)

            {

                HttpPostedFile PostedFile = Request.Files[p];

                if (PostedFile.ContentLength > 0)

                {

                    string uploadName = PostedFile.FileName;

                    string fileName = System.IO.Path.GetFileName(PostedFile.FileName);

                    string path = Path.GetFileName(FileUpload1.FileName);


                    ftpfile(@"/wwwroot/CSSite/Uploads/aaa.rar", @"\\TOM-\Users\Public\Documents\Tr2.rar");

                    //   ftpfile(@"/wwwroot/CSSite/Uploads/" + fileName, @"" + path + "/" + uploadName);

                }

            }

        }


        public void ftpfile(string ftpfilepath, string inputfilepath)

        {

            string ftphost = "127.0.0.1";

            string ftpfullpath = "ftp://" + ftphost + ftpfilepath;

            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);

            ftp.Credentials = new NetworkCredential("id", "pwd");

            ftp.Proxy = new WebProxy();

            ftp.KeepAlive = true;

            ftp.UseBinary = true;

            ftp.Method = WebRequestMethods.Ftp.UploadFile;

            FileStream fs = File.OpenRead(inputfilepath);

            byte[] buffer = new byte[fs.Length];

            fs.Read(buffer, 0, buffer.Length);

            fs.Close();

            Stream ftpstream = ftp.GetRequestStream();

            ftpstream.Write(buffer, 0, buffer.Length);

            ftpstream.Close();

        }

    }



    I've tried to use VS2008 and set the breakpoint, it can functionally work. (get the full path from client side, and upload successfully)


    However, when I deploy the coding into IIS in the same machine, it shows error that cannot find the path like C:\Windows\System32\(myDoc).extension


    but actually my upload path was (for example: C:\Users\Tom320\Documents\(myDoc).extension)


     


    Thank you !


  • Genady Sergeev Genady Sergeev admin's avatar

    Posted on Mar 7, 2011 (permalink)

    Hello Tom,

    Please make the distinction between client and server. You are trying the to access client-side path on the server. On your local machine it may work, (since it is both client and server) but will fail elsewhere. Instead of obtaining the stream through path please use the InputStream property provided by the PostedFile class.

    Greetings,
    Genady Sergeev
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Upload > FTP with ASP.NET - get client upload path