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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:03:26+00:00 2026-05-26T06:03:26+00:00

I wrote this code to download a file from an FTP server. When the

  • 0

I wrote this code to download a file from an FTP server. When the program tries to download and save the file, I get an access denied error. I tried opening the program with admin rights, but it gives the same error.

WebClient request = new WebClient();
request.Credentials = new NetworkCredential(txtFTPuser.Text,
                                            txtFTPpassword.Text);
/*List all directory files*/
byte[] fileData = request.DownloadData(fullDownloaPath);//dnoces.dreamhost.com
FileStream fi = File.Create(downloadTo);
fi.Write(fileData, 0, fileData.Length);
fi.Close();
MessageBox.Show("Completed!");

enter image description here

  • 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-26T06:03:26+00:00Added an answer on May 26, 2026 at 6:03 am

    You need to provide the full file path in your call to File.Create. Right now, you’re trying to overwrite your “Games” directory with the file you’re downloading, and that’s no good.

    Try setting downloadTo to something like C:\Users\agam\Desktop\Games\myfile.ext instead of, as it’s likely set to now, C:\Users\agam\Desktop\Games\.


    As an aside, there are two obvious improvements to your code I’d encourage you to look at:

    • Use the DownloadFile method of WebClient, rather than DownloadData, to save you some effort.
    • Wrap the creation of your WebClient in a using call to ensure that it’s closed even if your method encounters an exception. Otherwise, you risk a leak of resources held by the client.

    For example:

    using (WebClient request = new WebClient())
    {
        request.Credentials = new NetworkCredential(txtFTPuser.Text,
                                                    txtFTPpassword.Text);
        request.DownloadFile(fullDownloadPath, downloadTo);
        MessageBox.Show("Completed!");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So far i wrote a code to download a file from ftp server then
I’m using the following code to download a file from a remote ftp server:
I was using this code to download a pdf file from server but it
I'm using this code for download files from a server via FTP. It works
i wrote code to download jquery file from google CDN first and if not
I want to download a file from a FTP server in the other Thread.
I'm using this Java code to download a file from the Internet: String address
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
I wrote this code. The constructor works normally, but in the destructor I get
If I wrote this code: typeof(myType).TypeHandle Would it use reflection? How much different from:

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.