Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7655697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:34:44+00:00 2026-05-31T12:34:44+00:00

I have the following code to upload a pdf file through ftp : try

  • 0

I have the following code to upload a pdf file through ftp :

try
        {
            if (!File.Exists(localPath))
                throw new FileNotFoundException(localPath);

            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(ftpPath));
            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.Proxy = null;
            request.UseBinary = true;
            request.Credentials = new NetworkCredential(username, password);

            byte[] data = File.ReadAllBytes(localPath);

            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
            if (response == null || (response.StatusCode != FtpStatusCode.CommandOK))
                throw new Exception("Upload failed.");
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
            throw e;
        }

My problem that it uploads only text without images . How could i upload a file without reading it? I mean i just want to select and rename the file and upload it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:34:45+00:00Added an answer on May 31, 2026 at 12:34 pm

    Use the WebClient class and use then the UploadFile Method.
    From msdn

     String uriString = Console.ReadLine();
    
    // Create a new WebClient instance.
    WebClient myWebClient = new WebClient();
    myWebClient.Credentials=new NetworkCredential(username, password);
    Console.WriteLine("\nPlease enter the fully qualified path of the file to be uploaded to the URI");
    string fileName = Console.ReadLine();
    Console.WriteLine("Uploading {0} to {1} ...",fileName,uriString);
    
    // Upload the file to the URI.
    // The 'UploadFile(uriString,fileName)' method implicitly uses HTTP POST method.
    byte[] responseArray = myWebClient.UploadFile(uriString,fileName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that adds a file upload option to a div
Hi I have the following piece of code to upload a file to Sharepoint.
I have the following code to upload a file to the server. For some
I have following file upload code: package net.viralpatel.contact.controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller;
I have the following html code to upload an image: <input type=file name=before size=40>
I have the following code: HTML <label>File Upload: </label> <input type=file name=file[] /> jQuery
Please can someone help? I have the following code which uploads a file to
I have following code class User attr_accessor :name end u = User.new u.name =
We have following code: try { // some code throwing MyException } catch (MyException
I have the following code sample upload3.php: <html> <head> <title>PHP Form Upload</title> </head> <body>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.