If you try to connect to FTP more than 3 times in C#, a job timeout error occurs.

JunYoungLee 161 Reputation points
2022-05-29T05:20:10.383+00:00

I'm working on C# WPF, .NET 4.8 Visual Studio 2022 environment.
I'm making an FTP access program, and it's okay to connect to the same FTP address twice, but when I connect the third time, an error occurs saying that the connection time has expired.
I don't know why this error occurs.
I attached my code.
help me.

private void Local1_TrBtn_Click(object sender, RoutedEventArgs e)
        {
            FtpWebRequest ftpReq = (FtpWebRequest)WebRequest.Create(uiList_textbox[2].Text);                   
            ftpReq.Credentials = new NetworkCredential(source_ftp_info1["id"], source_ftp_info1["pw"]);
            ftpReq.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
            ftpReq.Timeout = ftp_timeout;
            FtpWebResponse resFtp = (FtpWebResponse)ftpReq.GetResponse();
        }
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,667 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
762 questions
{count} votes

2 answers

Sort by: Most helpful
  1. T. Kujala 8,696 Reputation points
    2022-05-29T05:40:32.067+00:00
    0 comments No comments

  2. Ken Tucker 5,846 Reputation points
    2022-05-29T09:37:40.083+00:00

    FYI Microsoft recommends you do not use the FTPWebRequest any more.

    https://github.com/dotnet/platform-compat/blob/master/docs/DE0003.md

    0 comments No comments