NAT Problem - SmartFTP FTP Library dll

Hi,

I'm setting up an FXP transfer. I set up the source server as follows in VB.NET:

Setup:
objFTP.Host = "ftp.test.com
objFTP.Port = "4000"
objFTP.Protocol = enumProtocol.ftpProtocolNormal
objFTP.Username = "test"
objFTP.Password = "test"
objFTP.MLST = False
objFTP.Passive = False
objFTP.LogFile = "c:testFTPSource.log"

Connection:
objFTP.Connect()
objFTP.ChangeDirectory("/TEST")
objFTP.ReadDirectory()

So, I can connect to the server and change directory without any problem, but when I try to read the directory, the log shows the following error message:

[20050413 02:01:28] PORT 10,0,0,150,10,136
[20050413 02:01:28] 501- ==YOU'RE BEHIND A NAT ROUTER==
[20050413 02:01:28] 501- Configure the firewall settings of your FTP client
[20050413 02:01:28] 501- to use your real IP: x.x.x.x (My real IP here)
[20050413 02:01:28] 501- And set up port forwarding in your router.
[20050413 02:01:28] 501- Or you can just use a PRET capable client

I'm indeed behind a NAT router. So I added the following lines to my code:
objFTP.PortMode = enumPortMode.ftpPortModeManual
objFTP.PortIP = "x.x.x.x" (My real IP here)

Still I can connect and change the directory, but when trying to read the directory, this error message:

[20050413 02:04:19] PORT x,x,x,x,10,138 (My real IP here)
[20050413 02:04:20] 200 Command okay
[20050413 02:04:20] LIST
[20050413 02:04:20] 150 File status okay; about to open data connection.
[20050413 02:04:50] Transfer Timeout. Closing data connection.
[20050413 02:05:20] Timeout (30s).
[20050413 02:05:20] Client closed the connection.

In most FTP clients (GUI), I just enable 'PRET Support' and everything works fine. Those logs show something like this:

[2] 250 Directory changed to /TEST
[2] PWD
[2] 257 "/TEST" is current directory
[2] PRET LIST
[2] 200 OK, will use master for upcoming transfer
[2] PASV
[2] 227 Entering Passive Mode (x,x,x,x,239,47). (Servers IP here)
[2] Opening data connection IP: x.x.x.x PORT: 4000
[2] LIST
[2] 150 File status okay; about to open data connection.
[2] 226 Closing data connection
[2] List Complete: 350 bytes in 0,31 seconds (1,12KB/s)

I tried all kind of settings but I can't get directory reading working with the smartFTP FTP Library dll on my PC behind NAT. I even tried to send the RAW command 'PRET LIST' to the server just before trying to read the directory, but still I got error messages.

Anybody can help or direct me to a solution?

Thx,
djrud

Hi,

First of all there were some minor bugs in the smartFTP FTP Libray with using the PRET command when in passive mode. They are fixed from version 1.0.1.15. So download that one please.

(It is important that the server supports PRET, you can check this if it is in the list that the server replies after the FEAT command)

So can connect to a dtFTPd server in passive mode when you are behind a router and using NAT using the next code:

objFTPS.Host = "<server IP>"
objFTPS.Port = "<port>"
objFTPS.Username = "<your login>"
objFTPS.Password = "<your passwd>"
objFTPS.Passive = True

With the fix in version 1.0.1.15 the librabary will use the following command sequence when using objFTPS.ReadDirectory() and the directory will be read fine:

PRET LIST
PASV
LIST

Connecting in to a drFTPD servr in active mode when behind a router and using NAT is also possible. Use this style of code:

Dim objFTPPortPool As sfFTPLib.FTPPortPoolClass
objFTPPortPool = New sfFTPLib.FTPPortPoolClass
objFTPPortPool.SetPortRange(5000, 5010) <--- A port range I opened manually on my router, you can choose you own range

objFTP.Host = "<server IP>"
objFTP.Port = "<Port>"
objFTP.Username = "<your login>"
objFTP.Password = "<your passwd>"
objFTP.Passive = False <--- Active mode
objFTP.LimitLocalPortRange = True <--- Limits the used ports to the ones you opened on your router
objFTP.PortMode = enumPortMode.ftpPortModeManual
objFTP.PortIP = "x.x.x.x" <--- Your public IP here
Dim intTest As Integer = objFTPPortPool.NextPort

Using objFTP.ReadDirectory() will then also work without a problem!

Greetz,
djrud