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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:08:07+00:00 2026-06-13T23:08:07+00:00

I am trying to upload a folder (and its content) through FTP but when

  • 0

I am trying to upload a folder (and its content) through FTP but when I try to do it, I keep getting an error saying no file is selected.

Do you know any way to make it so it’ll upload the folder and its content?

Here’s the code I am using. (I want to upload all the files in the folder Plugins):

UploadFile(@"C:\\MainPlugins\\Plugins", "ftp://testsiteurl.com/public_html/wp-content/plugins/test plugin", "username", "password");

This is the sub I am using:

public void UploadFile(string _FileName, string _UploadPath, string _FTPUser, string _FTPPass)
{
    System.IO.FileInfo _FileInfo = new System.IO.FileInfo(_FileName);

    // Create FtpWebRequest object from the Uri provided
    System.Net.FtpWebRequest _FtpWebRequest = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(new Uri(_UploadPath));

    // Provide the WebPermission Credintials
    _FtpWebRequest.Credentials = new System.Net.NetworkCredential(_FTPUser, _FTPPass);

    // By default KeepAlive is true, where the control connection is not closed
    // after a command is executed.
    _FtpWebRequest.KeepAlive = false;

    // set timeout for 20 seconds
    _FtpWebRequest.Timeout = 20000;

    // Specify the command to be executed.
    _FtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile;

    // Specify the data transfer type.
    _FtpWebRequest.UseBinary = true;

    // Notify the server about the size of the uploaded file
    _FtpWebRequest.ContentLength = _FileInfo.Length;

    // The buffer size is set to 2kb
    int buffLength = 2048;
    byte[] buff = new byte[buffLength];

    // Opens a file stream (System.IO.FileStream) to read the file to be uploaded
    System.IO.FileStream _FileStream = _FileInfo.OpenRead();

    try
    {
        // Stream to which the file to be upload is written
        System.IO.Stream _Stream = _FtpWebRequest.GetRequestStream();

        // Read from the file stream 2kb at a time
        int contentLen = _FileStream.Read(buff, 0, buffLength);

        // Till Stream content ends
        while (contentLen != 0)
        {
            // Write Content from the file stream to the FTP Upload Stream
            _Stream.Write(buff, 0, contentLen);
            contentLen = _FileStream.Read(buff, 0, buffLength);
        }

        // Close the file stream and the Request Stream
        _Stream.Close();
        _Stream.Dispose();
        _FileStream.Close();
        _FileStream.Dispose();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Upload Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
  • 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-06-13T23:08:08+00:00Added an answer on June 13, 2026 at 11:08 pm

    Your URI is incorrect, you need to specify the file name in the URI.

    // Create FtpWebRequest object from the Uri provided
        System.Net.FtpWebRequest _FtpWebRequest = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(new Uri(_UploadPath + "/" + _FileInfo.Name));
    

    Also, consider using the “using” keyword for your streams to properly dispose them in case of an exception.

    using (System.IO.FileStream _FileStream = _FileInfo.OpenRead())
                    {
    
                        // Stream to which the file to be upload is written
    
                        using (System.IO.Stream _Stream = _FtpWebRequest.GetRequestStream())
                        {
                            // Read from the file stream 2kb at a time
                            int contentLen = _FileStream.Read(buff, 0, buffLength);
    
                            // Till Stream content ends
                            while (contentLen != 0)
                            {
                                // Write Content from the file stream to the FTP Upload Stream
                                _Stream.Write(buff, 0, contentLen);
                                contentLen = _FileStream.Read(buff, 0, buffLength);
                            }
    
                            //No need to Close the file stream and the Request Stream
    
                        }
                    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to upload images to a php file, everything works, but sometimes when
I'm trying to upload a rails app to dotcloud. I'm getting this error: PG::Error
I'm trying to upload a file .txt in my web space, but then the
I'm trying to upload a file and change its name below. I need to
I am trying to upload an image,create thumbnail but i get an error. Here
I'm trying to upload an image file from an android device to my drupal
I am trying to upload file to an sharepoint online server using webclient. Up
I'm trying to create a custom file upload control in WPF 4.0 and I'm
I'm trying to create an FTP script that will copy a local folder structure
I'm looking for some help with PHP File Upload. I'm trying to upload an

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.