question

JunYoungLee-5266 avatar image
0 Votes"
JunYoungLee-5266 asked vb2ae answered

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

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-wpfdotnet-wpf-xaml
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Maybe you should call resFtp.Close or resfFtp.Dispose (or use the using statement) at the end of processing. Check if this helps.

0 Votes 0 ·
TKujala avatar image
0 Votes"
TKujala answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

vb2ae avatar image
0 Votes"
vb2ae answered

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

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.