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 6371681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:06:44+00:00 2026-05-25T01:06:44+00:00

This seems like a trivial problem, but my web searches for an answer (even

  • 0

This seems like a trivial problem, but my web searches for an answer (even on this site) have forced me to ask the question explicitly.

I am uploading a file via FTP from my server to a remote server. My code looks like this…

public void Upload(string fileToUpload)
    {
        // Get the object used to communicate with the server.
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.remoteserver.com/Data/" + fileToUpload);
        request.UsePassive = false;
        request.UseBinary = true;
        request.Method = WebRequestMethods.Ftp.UploadFile;
        request.Credentials = new NetworkCredential ("username","password");

        // Copy the contents of the file to the request stream.
        StreamReader sourceStream = new StreamReader(fileToUpload);
        byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
        sourceStream.Close();
        request.ContentLength = fileContents.Length;

        Stream requestStream = request.GetRequestStream();
        requestStream.Write(fileContents, 0, fileContents.Length);
        requestStream.Close();

        FtpWebResponse response = (FtpWebResponse)request.GetResponse();

        Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

        response.Close();
    }

This all seems very straight-forward. The problem I am having is that I get a 550 error when the file does not already exist on the remote server. I would assume that if the file doe snot exist, then the file would be created. Further, I assume that if it does that it will be overwritten.

Since this is not the case (at least with writing a new file), I would further assume that I should (a) somehow check for the file first, and (b) create it if it does not exist. But how to do this?

Thanks,

Mike

  • 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-25T01:06:45+00:00Added an answer on May 25, 2026 at 1:06 am

    (comment converted to answer)

    What are you passing into fileToUpload, an absolute file path such as c:\File.txt or just a filename like File.txt? Also, do you understand that your program only works with text files, right?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like an incredibly dumb question to have to ask, but how do
This seems like such a trivial question to ask, but it's been vexing me
This seems like such a trivial problem, but I can't seem to pin how
This seems like a pretty softball question, but I always have a hard time
This seems like a trivial problem, but it has me kind of stumped. I
This seems like a simple question, but I can't find it with the Stack
This seems like a silly question but I would really like your comments and
This seems like perhaps a naive question, but I got into a discussion with
This seems like a basic question, but I haven't found any clear answers. Essentially,
I have problem that seems to be rather trivial but I was not able

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.