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

  • Home
  • SEARCH
  • 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 9004005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:48:09+00:00 2026-06-16T00:48:09+00:00

Possible Duplicate: How can I programmatically remove the 2 connection limit in WebClient My

  • 0

Possible Duplicate:
How can I programmatically remove the 2 connection limit in WebClient

My FTP script was working great until I started to try and run multiple threads at once. After excessive debugging it turns out the FtpWebRequest simply times out if two other threads are already doing something. (Uploading, checking if a file/directory exists or creating a directory.)

I already tried implementing a lock in the ftp class so that only one thread can ever create an FtpWebRequest at a time (and then close the lock when getting the response ofc) but that didn’t help.

Each request uses it’s own FtpWebRequest object so I’m not quite sure why this is happening. I can upload 10 files simultaneously to the same FTP server when using the FileZilla client so I can’t imagine it’s a problem on the server’s end.

Is there some static behind-the-scenes thing in .NET that is causing this issue?

Example function that times out >2 threads:

public class ftp
{
    private string host = null;
    private string user = null;
    private string pass = null;
    private int bufferSize = 2048;

    /* Construct Object */
    public ftp(string hostIP, string userName, string password) { host = hostIP; user = userName; pass = password; }

    private object fileFolderCheckLock = new object(); //Only check if a file/dir exists one thread at a time
    private object requestLock = new object(); //Don't create multiple ftprequests simultaneously. Exit this lock when the response is being received.

    /* Create a New Directory on the FTP Server */
    public bool CreateDirectory(string newDirectory)
    {
        FtpWebRequest ftpRequest = null;
        FtpWebResponse ftpResponse = null;
        try
        {
            lock(requestLock)
            {
                if(!newDirectory.EndsWith("/")) newDirectory += "/";
                //Console.WriteLine("chk: "+host + "/" + newDirectory);
                Uri theuri = new Uri(host + "/" + newDirectory);
                //Console.WriteLine("theuri: "+theuri.ToString());
                /* Create an FTP Request */
                ftpRequest = (FtpWebRequest)WebRequest.Create(theuri);
                /* Log in to the FTP Server with the User Name and Password Provided */
                ftpRequest.Credentials = new NetworkCredential(user, pass);
                /* When in doubt, use these options */
                ftpRequest.UseBinary = true;
                ftpRequest.UsePassive = true;
                ftpRequest.KeepAlive = true;
                ftpRequest.Timeout = 10000;
                /* Specify the Type of FTP Request */
                ftpRequest.Method = WebRequestMethods.Ftp.MakeDirectory;
                /* Establish Return Communication with the FTP Server */
                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
            }
        }
        catch (Exception ex){ Console.WriteLine("CreateDirectory Exception"+ex.ToString()); }
        finally
        {
            /* Resource Cleanup */
            try{ftpResponse.Close();}catch(Exception){}//??
            ftpRequest = null;
        }
        return true;
    }
}

Can anyone tell me why this happens?

  • 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-16T00:48:11+00:00Added an answer on June 16, 2026 at 12:48 am

    You are probably hitting the default maximum connections. Take a look at this: How can I programmatically remove the 2 connection limit in WebClient

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

Sidebar

Related Questions

Possible Duplicate: Can I scroll a ScrollView programmatically in Android? I have a chat
Possible Duplicate: Can anybody suggest the best image resize script in php? I'm still
Possible Duplicate: How do i programmatically change file permissions? How can I set the
Possible Duplicate: Detecting endianness programmatically in a C++ program I am working on a
Possible Duplicate: How can I beautify JSON programmatically? I have build a code generator
Possible Duplicate: return a specific http status code with php How can I programmatically
Possible Duplicate: In JavaScript can I make a “click” event fire programmatically for a
Possible Duplicate: Programmatically find device support GPS or not? How can I check, is
Possible Duplicate: How can you programmatically tell an HTML SELECT to drop down (for
Possible Duplicate: How can we programmatically detect which iOS version is device running on?

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.