Hi All!
I'm hoping that someone can help me with an annoying connection problem I'm having...
The problem
-----------
I'm having a problem using the Secure SDK to connect to an WS_FTP server.
The problem is that the SDK functions always give the error "425 Can't open data connection" when I try to list the contents of an FTP directory.
WS_FTP Pro, however, works fine.
Software Versions
-----------------
The WS_FTP Server is version 5.01 (with the latest July patch).
The WS Secure SDK is the latest version.
The Server operating system is Windows 2000 Server.
The Client operating system is Windows XP or Windows 2000 Professional (it fails on both).
Both the Server AND the client machines are behind NAT firewalls.
FTP Settings
------------
The significant settings for the WS_FTP Server are as follows:
General System Settings: FTP Port = 1961
Firewall options: IP Address = left blank. Port Range = 1962-1969
SSL: Enable SSL = checked, Force Clients to use SSL Connections = checked, Force Clients to use 128-bit or higher on this host = checked.
More Details
------------
Like I already said, it works fine if you use WS_FTP PRO to access the FTP directory (note: there is no firewall configuration selected for WS_FTP PRO).
The SDK also works if the client does NOT use a NAT firewall, i.e. if you go directly onto the Internet or via Zone Alarm it works fine!
This leads me to conclude that the problem is related to using a NAT firewall on the client. However, the fact that WS_FTP PRO works WITHOUT you having to specify any firewall details should mean that the SDK should also work!
Code
----
Here is the C# code that fails through a NAT firewall:
using FTP = WsftpSDK ;
FTP.WsftpApiClass ftp = new WsftpSDK.WsftpApiClass();
FTP.WsftpConnection connex = ftp.CreateConnection
(
"ftp.ouraddress.com",
"account",
"*******",
(int)FTP.WsftpConnectionTypes.WSFTP_CT_FTPAUTHSSL,
1961
);
FTP.WsftpFolder folder = connex.GetFolder( "*", "/SymphonetData" );
folder.Refresh();
string file_list = "File list:\r\r" ;
for ( int i = 0, n = folder.Count ; i < n ; ++i )
{
FTP.WsftpItem item = folder.get_Item(i);
file_list += item.Name + "\r" ;
}
MessageBox.Show( file_list ); // File list is always empty.
connex.Disconnect();
Comments on the code
--------------------
If I look at connex.LastServerResponse immediately after the call to connex.GetFolder(), it says:
"425 Can't open data connection."
Then folder.Count is zero (even though the folder contains many items).
Logs
----
Comparing the WS_FTP_PRO logs and the not-working SDK logs seems to point to the culprit being the SDK's inability to substitute a connection address for a private address.
===========================
Working log from WS_FTP PRO
===========================
PWD
257 "/SymphonetData" is current directory
TYPE A
200 Type set to ASCII.
PASV
227 Entering Passive Mode (10,0,0,3,7,170).
connecting data channel to 10.0.0.3:7,170(1962)
Substituting connection address 195.173.199.130 for private address 10.0.0.3 from PASV
data channel connected to 195.173.199.130:7,170(1962)
MLSD
150 Opening ASCII data connection for directory listing
transferred 1171 bytes in < 0.001 seconds, 9148.438 Kbps ( 1143.555 Kbps), transfer succeeded.
226 transfer complete
=====================================
Not working log from SDK test program
=====================================
[2004.07.23 14:20:05.638] PWD
[2004.07.23 14:20:05.654] 257 "/SymphonetData" is current directory
[2004.07.23 14:20:05.669] TYPE A
[2004.07.23 14:20:05.685] 200 Type set to ASCII.
[2004.07.23 14:20:05.685] PASV
[2004.07.23 14:20:05.700] 227 Entering Passive Mode (10,0,0,3,7,177).
[2004.07.23 14:20:05.700] connecting data channel to 10.0.0.3:7,177(1969)
[2004.07.23 14:20:26.666] PORT 192,168,12,155,5,6
[2004.07.23 14:20:26.682] 200 command successful
[2004.07.23 14:20:26.682] MLSD *
[2004.07.23 14:20:49.647] 425 Can't open data connection.
[2004.07.23 14:20:49.772] PORT 192,168,12,155,5,7
[2004.07.23 14:20:49.788] 200 command successful
[2004.07.23 14:20:49.788] MLSD
[2004.07.23 14:21:12.726] 425 Can't open data connection.
[2004.07.23 14:21:15.242] QUIT
[2004.07.23 14:21:15.273] 221 Good-Bye
Note the line from the working WS_PRO that says "Substituting connection address 195.173.199.130 for private address 10.0.0.3 from PASV".
There seems to be no equivalent in the SDK version.
I'm well and truly stuck at this point! Any help would be most appreciated!