Catch TcpClient ctor exceptions in FtpWebRequest.CreateConnectionAsync (#56379)
authorStephen Toub <stoub@microsoft.com>
Wed, 28 Jul 2021 01:50:15 +0000 (21:50 -0400)
committerGitHub <noreply@github.com>
Wed, 28 Jul 2021 01:50:15 +0000 (21:50 -0400)
src/libraries/System.Net.Requests/src/System/Net/FtpWebRequest.cs

index 157d9f4..74dde85 100644 (file)
@@ -967,15 +967,11 @@ namespace System.Net
 
         private async void CreateConnectionAsync()
         {
-            string hostname = _uri.Host;
-            int port = _uri.Port;
-
-            TcpClient client = new TcpClient();
-
             object result;
             try
             {
-                await client.ConnectAsync(hostname, port).ConfigureAwait(false);
+                var client = new TcpClient();
+                await client.ConnectAsync(_uri.Host, _uri.Port).ConfigureAwait(false);
                 result = new FtpControlStream(client);
             }
             catch (Exception e)