|
8 | 8 | using System.Linq; |
9 | 9 | using GeneXus.Encryption; |
10 | 10 | using GeneXus.Configuration; |
| 11 | +using log4net; |
11 | 12 |
|
12 | 13 | namespace GeneXus.Utils |
13 | 14 | { |
14 | 15 | [SecuritySafeCritical] |
15 | 16 | public class FtpService |
16 | 17 | { |
| 18 | + private static readonly ILog log = log4net.LogManager.GetLogger(typeof(FtpService)); |
17 | 19 |
|
18 | 20 | private Socket _DataSocket; |
19 | 21 | private Socket _ControlSocket; |
@@ -511,8 +513,7 @@ private void OpenDataConnection() |
511 | 513 | } |
512 | 514 | _DataSocket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ); |
513 | 515 |
|
514 | | - IPHostEntry localHostEntry = Dns.GetHostEntry(Dns.GetHostName()); |
515 | | - IPAddress hostAddress = localHostEntry.AddressList.First(a => (a.AddressFamily == _DataSocket.AddressFamily)); ; |
| 516 | + IPAddress hostAddress = GetIpAddress(Dns.GetHostName()); |
516 | 517 | IPEndPoint epListener = new IPEndPoint(hostAddress, 0); |
517 | 518 | _DataSocket.Bind(epListener); |
518 | 519 |
|
@@ -565,8 +566,7 @@ private void OpenPassiveDataConnection() |
565 | 566 | { |
566 | 567 | ProcessProtocolViolationError("Error in creating Data Socket"); |
567 | 568 | } |
568 | | - IPHostEntry serverHostEntry = Dns.GetHostEntry(_RequestUri.Host); |
569 | | - IPAddress hostAddress = serverHostEntry.AddressList.First(a => (a.AddressFamily == _DataSocket.AddressFamily)); ; ; |
| 569 | + IPAddress hostAddress = GetIpAddress(_RequestUri.Host); |
570 | 570 | IPEndPoint serverEndPoint = new IPEndPoint(hostAddress, Port); |
571 | 571 |
|
572 | 572 | try |
@@ -631,10 +631,8 @@ private void OpenControlConnection(Uri uriToConnect) |
631 | 631 | clientEndPoint = _ControlSocket.LocalEndPoint; |
632 | 632 | try |
633 | 633 | { |
634 | | - IPHostEntry serverHostEntry = Dns.GetHostEntry(Host); |
635 | | - IPAddress ipAddresses = serverHostEntry.AddressList.First(a => (a.AddressFamily == _ControlSocket.AddressFamily)); |
| 634 | + IPAddress ipAddresses = GetIpAddress(Host); |
636 | 635 | IPEndPoint serverEndPoint = new IPEndPoint(ipAddresses, Port); |
637 | | - |
638 | 636 | try |
639 | 637 | { |
640 | 638 | if (GXUtil.IsWindowsPlatform) |
@@ -679,6 +677,21 @@ private void OpenControlConnection(Uri uriToConnect) |
679 | 677 | } |
680 | 678 | } |
681 | 679 |
|
| 680 | + private IPAddress GetIpAddress(string host) |
| 681 | + { |
| 682 | + IPHostEntry serverHostEntry = Dns.GetHostEntry(host); |
| 683 | + IPAddress ipAddresses = serverHostEntry.AddressList.FirstOrDefault(); |
| 684 | + GXLogging.Debug(log, $"GetHostEntry({host}) AddressList length: ", serverHostEntry.AddressList.Length.ToString()); |
| 685 | + if (ipAddresses == null) |
| 686 | + { |
| 687 | + serverHostEntry = Dns.GetHostByName(host); |
| 688 | + ipAddresses = serverHostEntry.AddressList.FirstOrDefault(); |
| 689 | + GXLogging.Debug(log, $"GetHostByName({host}) AddressList length: ", serverHostEntry.AddressList.Length.ToString()); |
| 690 | + } |
| 691 | + GXLogging.Debug(log, "HostAddress ", ipAddresses.ToString()); |
| 692 | + return ipAddresses; |
| 693 | + } |
| 694 | + |
682 | 695 | void CloseDataConnection() |
683 | 696 | { |
684 | 697 | if(_DataSocket != null) |
@@ -976,19 +989,19 @@ internal void ProcessApplicationError( string s) |
976 | 989 | { |
977 | 990 | this._status = 1; |
978 | 991 | this._statusDescription = s; |
979 | | - |
| 992 | + GXLogging.Error(log, "ProcessApplicationError " + s); |
980 | 993 | } |
981 | 994 | internal void ProcessApplicationError( string s, Exception e) |
982 | 995 | { |
983 | 996 | this._status = 1; |
984 | 997 | this._statusDescription = s + e.Message; |
985 | | - |
| 998 | + GXLogging.Error(log, "ProcessApplicationError " + s, e); |
986 | 999 | } |
987 | 1000 | internal void ProcessProtocolViolationError( string s) |
988 | 1001 | { |
989 | 1002 | this._status = 1; |
990 | 1003 | this._statusDescription = new ProtocolViolationException(s).ToString(); |
991 | | - |
| 1004 | + GXLogging.Warn(log, "ProcessProtocolViolationError ", this._statusDescription); |
992 | 1005 | } |
993 | 1006 | internal string ComposeExceptionMessage(ResponseDescription resp_desc, string log) |
994 | 1007 | { |
|
0 commit comments