+1 vote

Hi
I am testing your tool for our company
need to connect to a server which supports active mode only
having difficulties to connect even if I am using

    Limilabs.FTP.Log.Enabled = True
    f.Mode = FTP.Client.FtpMode.Active
    f.DontUseCompression = True

    f.TransfersDataType = FTP.Client.FtpDataType.Ascii
    f.Connect(ftpserver)
    f.Login(ftpuser, ftppassword)

Connecting via Filzezilla is fine
using FTP protocoll :21
encryption: only use plain FTP
What the hell I am doing wrong ?

Sven

by
Please don't set the TransfersDataType - most likely it's not needed.

What error/exception are you getting?

1 Answer

0 votes

Consider using passive mode - it's much more common:

' f.Mode = FTP.Client.FtpMode.Passive (default)

f.Connect(ftpserver)
f.Login(ftpuser, ftppassword)
by (301k points)
Hi
as mentioned in my question
FTP server supports active mode only
If I use active mode I am getting timeout..tried to read a line only '' received.... and so on
If I am using the default passive I get the message:
Can't open passive connection

Using Filezilla client I can connect
Sven
What is the stack trace?
Logs (https://www.limilabs.com/blog/logging-in-ftp-dll)?
At what line exactly you get this error?

Is your firewall properly configured? - Check inbound rules for your app.
hi,

it happens here

f.Mode = FTP.Client.FtpMode.Active
response = f.Upload(DestinationFilname, SourceFileName)

I am using this app to connect to different FTP Servers
all are going ok, but only passive mode drives me nuts



Ftp.dll Information: 0 :  9 23:11:49 Control connection uses port: 60616 (236,200)
Ftp.dll Information: 0 :  9 23:11:49 S: 220-FTP 21:11:55 on 2016-10-14.
Ftp.dll Information: 0 :  9 23:11:49 S: 220 Connection will close if idle for more than 30 minutes.
Ftp.dll Information: 0 :  9 23:11:49 C: USER xxxxx
Ftp.dll Information: 0 :  9 23:11:49 S: 331 Send password please.
Ftp.dll Information: 0 :  9 23:11:49 C: PASS xxxxxxx
Ftp.dll Information: 0 :  9 23:11:50 S: 230 xxx is logged on.  Working directory is "/ftp/xxx".
Ftp.dll Information: 0 :  9 23:11:50 C: FEAT
Ftp.dll Information: 0 :  9 23:11:50 S: 211- Extensions supported
Ftp.dll Information: 0 :  9 23:11:50 S:  MDTM
Ftp.dll Information: 0 :  9 23:11:50 S:  AUTH TLS
Ftp.dll Information: 0 :  9 23:11:50 S:  PBSZ
Ftp.dll Information: 0 :  9 23:11:50 S:  PROT
Ftp.dll Information: 0 :  9 23:11:50 S: 211 End
False
Ftp.dll Information: 0 :  9 23:11:54 C: TYPE A
Ftp.dll Information: 0 :  9 23:11:54 S: 200 Representation type is Ascii NonPrint
Ftp.dll Information: 0 :  9 23:11:54 C: PASV
Ftp.dll Information: 0 :  9 23:11:54 S: 425 Can't open passive connection.
in addition
this is what I am getting in passive mode

Ftp.dll Information: 0 :  9 23:30:03 C: FEAT
Ftp.dll Information: 0 :  9 23:30:03 S: 211- Extensions supported
Ftp.dll Information: 0 :  9 23:30:03 S:  MDTM
Ftp.dll Information: 0 :  9 23:30:03 S:  AUTH TLS
Ftp.dll Information: 0 :  9 23:30:03 S:  PBSZ
Ftp.dll Information: 0 :  9 23:30:03 S:  PROT
Ftp.dll Information: 0 :  9 23:30:03 S: 211 End
False
Ftp.dll Information: 0 :  9 23:30:20 C: TYPE A
Ftp.dll Information: 0 :  9 23:30:20 S: 200 Representation type is Ascii NonPrint
Ftp.dll Information: 0 :  9 23:30:20 Binding to: 10.218.6.48:0
Ftp.dll Information: 0 :  9 23:30:20 Bound to: 10.218.6.48:0
Ftp.dll Information: 0 :  9 23:30:20 C: PORT 10,218,6,48,238,180
Ftp.dll Information: 0 :  9 23:30:20 S: 200 Port request OK.
Ftp.dll Information: 0 :  9 23:30:20 C: STOR /ftp/ARRO494/incoming/Temp/FD6CNFF_ARROW_000004444_12001113_C1937_30_20160928153442.TXT
Exception thrown: 'Limilabs.FTP.Client.FtpException' in Ftp.dll

The exception is as described earlier
<  .tried to read a line only '' received.  >
What is the exception StackTrace?
Please don't set the transfer data type (remove this line f.TransfersDataType = FTP.Client.FtpDataType.Ascii).
Hi
this is the stack trace


Tried to read a line. Only '' received. Please make sure that antivirus and firewall software are disabled or configured correctly.



   at  .()
   at  .()
   at Limilabs.FTP.Client.FtpResponse.(  )
   at Limilabs.FTP.Client.Ftp.(Boolean )
   at Limilabs.FTP.Client.Ftp.Upload(String remotePath, Int64 remoteStartPosition, Stream source)
   at Limilabs.FTP.Client.Ftp.Upload(String remotePath, String localPath)
   at smallFTPClient.clsFTP.UPLoadFile(String SourceFileName, String DestinationFilname, String& Errormessage) in C:\Users\sreupke\Documents\SVN\Arrow_dev\Projects\VB\Power & Signal\Small FTP\clsFTP.vb:line 117
Hi
thanks already for your support :-)
I've removed the ASCII transfer type. Even this has been requested. Nothing has changed
I am getting same resultes

Ftp.dll Information: 0 :  8 23:42:31 2.0.16253.1842
Ftp.dll Information: 0 :  8 23:42:31 Connecting to 'ftp3.tnt.com:21', SSL: False.
Ftp.dll Information: 0 :  8 23:42:31 Control connection uses port: 61589 (240,149)
Ftp.dll Information: 0 :  8 23:42:31 S: 220-FTP 21:42:38 on 2016-10-14.
Ftp.dll Information: 0 :  8 23:42:31 S: 220 Connection will close if idle for more than 30 minutes.
Ftp.dll Information: 0 :  8 23:42:31 C: USER ARRO494
Ftp.dll Information: 0 :  8 23:42:32 S: 331 Send password please.
Ftp.dll Information: 0 :  8 23:42:32 C: PASS xxxx
Ftp.dll Information: 0 :  8 23:42:32 S: 230 xxxxis logged on.  Working directory is "/ftp/xxx".
Ftp.dll Information: 0 :  8 23:42:32 C: FEAT
Ftp.dll Information: 0 :  8 23:42:32 S: 211- Extensions supported
Ftp.dll Information: 0 :  8 23:42:32 S:  MDTM
Ftp.dll Information: 0 :  8 23:42:32 S:  AUTH TLS
Ftp.dll Information: 0 :  8 23:42:32 S:  PBSZ
Ftp.dll Information: 0 :  8 23:42:32 S:  PROT
Ftp.dll Information: 0 :  8 23:42:32 S: 211 End
False
Ftp.dll Information: 0 :  8 23:42:51 C: TYPE I
Ftp.dll Information: 0 :  8 23:42:51 S: 200 Representation type is Image
Ftp.dll Information: 0 :  8 23:42:51 Binding to: 10.218.6.48:0
Ftp.dll Information: 0 :  8 23:42:51 Bound to: 10.218.6.48:0
Ftp.dll Information: 0 :  8 23:42:51 C: PORT 10,218,6,48,240,153
Ftp.dll Information: 0 :  8 23:42:51 S: 200 Port request OK.
Ftp.dll Information: 0 :  8 23:42:51 C: STOR /ftp/ARRO494/incoming/Temp/FtpTrial-FD6CNFF_ARROW_000004444_12001113_C1937_30_20160928153442.TXT
Exception thrown: 'Limilabs.FTP.Client.FtpException' in Ftp.dll
The program '[14656] smallFTPClient.vshost.exe' has exited with code -1 (0xffffffff).
Does this happen when you invoke Ftp.List()? (it only downloads data)
Hi

yes !


Ftp.dll Information: 0 :  8 23:50:31 C: TYPE A
Ftp.dll Information: 0 :  8 23:50:31 S: 200 Representation type is Ascii NonPrint
Ftp.dll Information: 0 :  8 23:50:31 Binding to: 10.218.6.48:0
Ftp.dll Information: 0 :  8 23:50:31 Bound to: 10.218.6.48:0
Ftp.dll Information: 0 :  8 23:50:31 C: PORT 10,218,6,48,241,130
Ftp.dll Information: 0 :  8 23:50:31 S: 200 Port request OK.
Ftp.dll Information: 0 :  8 23:50:31 C: LIST
Exception thrown: 'Limilabs.FTP.Client.FtpException' in Ftp.dll
> PORT 10,218,6,48,241,130

10.218.6.48 is a local IP address. Is this IP available from the server?

If not please specify your public IP by using:

    f.ActiveModeAddress = IPAddress.Parse("w.x.y.z")
    f.Connect(...)
this is my IP
  IPv4 Address. . . . . . . . . . . : 10.218.6.48
Connecting to 'ftp3.tnt.com:21', SSL: False.

I can connect to this server using FileZilla "only use plain FTP"
there is no issue with FW
Log FileZilla:
------------------------------
Status:    Resolving address of ftp3.tnt.com
Status:    Connecting to 164.39.122.51:21...
Status:    Connection established, waiting for welcome message...
Status:    Server does not support non-ASCII characters.
Status:    Logged in
---------------------------------------------

If I would use any Encryption it will also not work with Filezilla (use explicit FTP over TLS if available e.g.)

I am leaving my office and make a test in different network (home office)
using public ip did not help too

Ftp.dll Information: 0 :  8 00:08:25 C: TYPE I
Ftp.dll Information: 0 :  8 00:08:25 S: 200 Representation type is Image
Ftp.dll Information: 0 :  8 00:08:25 Binding to: 10.218.6.48:0
Ftp.dll Information: 0 :  8 00:08:25 Bound to: 10.218.6.48:0
Ftp.dll Information: 0 :  8 00:08:25 C: PORT 212,61,40,130,243,54
Ftp.dll Information: 0 :  8 00:08:25 S: 200 Port request OK.
Ftp.dll Information: 0 :  8 00:08:25 C: STOR /ftp/ARRO494/incoming/Temp/FD6CNFF_ARROW_000004444_12001113_C1937_30_20160928153442.TXT
Exception thrown: 'Limilabs.FTP.Client.FtpException' in Ftp.dll
The thread 0x1e98 has exited with code 0 (0x0).
Your problem is not with connecting to the server.
The connection is established and you are able to login.

The problem starts when you try to transfer data to/from the server - this requires new connection and in case of active mode, it is the FTP server connects to your local machine.

PORT command tells the server which IP should it use (it sends the client's IP).
If the client sends its private address (like 192.168.0.2 or 10.0.0.2). FTP server won't be able to connect.

You can use https://www.whatismyip.com/ to get your public IP address.

Please note that your router must be smart enough to forward the server request for connection to your computer, which is in private network (NAT).
Can you create a test account for us?
Please use email in the bottom of this page.
Can you also send us detailed log from FileZilla?
To show complete, unabbreviated logs, you can right-click the log and select "Show detailed logs".

Then perform any operation - like download a file or upload a file.
Status:    Resolving address of ftp3.tnt.com
Status:    Connecting to 164.39.122.51:21...
Status:    Connection established, waiting for welcome message...
Response:    220-FTP 22:56:04 on 2016-10-14.
Response:    220 Connection will close if idle for more than 30 minutes.
Command:    USER ARRO494
Response:    331 Send password please.
Command:    PASS ********
Response:    230 ARRO494 is logged on.  Working directory is "/ftp/ARRO494".
Status:    Server does not support non-ASCII characters.
Status:    Logged in
Status:    Retrieving directory listing...
Command:    PWD
Response:    257 "/ftp/ARRO494" is the HFS working directory.
Command:    TYPE I
Response:    200 Representation type is Image
Command:    PORT 192,168,0,10,244,236
Response:    200 Port request OK.
Command:    LIST
Response:    125 List started OK
Response:    250 List completed successfully.
Status:    Directory listing of "/ftp/ARRO494" successful
I am at home office
that is why we see 192.... adress now :-)
I assume you get the same exception when using Ftp.dll....in that case we'll need a test account. I've no idea what may be wrong.

FileZilla logs are standard active FTP conversation, it should work with Ftp.dll without any issues.
Hi
that's what drives me crazy too.
I have created a FTP in the azure cloud allowing only active sessions.
Unfortunately I can not replicate the issue
It's working perfectly fine

Something is strange with the server setup...

  f.Mode = FtpMode.Active;
                f.DontUseCompression = true;
              
                f.TransfersDataType = FtpDataType.Ascii;
                f.Connect(ftpserver);
                f.Login(ftpuser, ftppassword);
                f.Upload("Test.txt", @"c:\temp\e.txt");
                f.Close();

Ftp.dll Information: 0 :  8 11:16:55 Connecting to '52.174.59.196:21', SSL: False.
Ftp.dll Information: 0 :  8 11:16:55 Control connection uses port: 64025 (250,25)
Ftp.dll Information: 0 :  8 11:16:56 S: 220-Microsoft FTP Service
Ftp.dll Information: 0 :  8 11:16:56 S: 220 Svenni FTP
Ftp.dll Information: 0 :  8 11:16:56 C: USER ***************
Ftp.dll Information: 0 :  8 11:16:56 S: 331 Password required
Ftp.dll Information: 0 :  8 11:16:56 C: PASS ***************
Ftp.dll Information: 0 :  8 11:16:56 S: 230-Welcome by Svenni FTP
Ftp.dll Information: 0 :  8 11:16:56 S: 230 User logged in.
Ftp.dll Information: 0 :  8 11:16:56 C: FEAT
Ftp.dll Information: 0 :  8 11:16:56 S: 211-Extended features supported:
Ftp.dll Information: 0 :  8 11:16:56 S:  LANG EN*
Ftp.dll Information: 0 :  8 11:16:56 S:  UTF8
Ftp.dll Information: 0 :  8 11:16:56 S:  AUTH TLS;TLS-C;SSL;TLS-P;
Ftp.dll Information: 0 :  8 11:16:56 S:  PBSZ
Ftp.dll Information: 0 :  8 11:16:56 S:  PROT C;P;
Ftp.dll Information: 0 :  8 11:16:56 S:  CCC
Ftp.dll Information: 0 :  8 11:16:56 S:  HOST
Ftp.dll Information: 0 :  8 11:16:56 S:  SIZE
Ftp.dll Information: 0 :  8 11:16:56 S:  MDTM
Ftp.dll Information: 0 :  8 11:16:56 S:  REST STREAM
Ftp.dll Information: 0 :  8 11:16:56 S: 211 END
Ftp.dll Information: 0 :  8 11:16:56 C: OPTS UTF8 ON
Ftp.dll Information: 0 :  8 11:16:56 S: 200 OPTS UTF8 command successful - UTF8 encoding now ON.
Ftp.dll Information: 0 :  8 11:16:57 C: TYPE A
Ftp.dll Information: 0 :  8 11:16:58 S: 200 Type set to A.
Ftp.dll Information: 0 :  8 11:16:58 Binding to: 192.168.2.12:0
Ftp.dll Information: 0 :  8 11:16:58 Bound to: 192.168.2.12:0
Ftp.dll Information: 0 :  8 11:16:58 C: PORT 192,168,2,12,250,26
Ftp.dll Information: 0 :  8 11:16:58 S: 200 PORT command successful.
Ftp.dll Information: 0 :  8 11:16:58 C: STOR Test.txt
Ftp.dll Information: 0 :  8 11:16:58 S: 125 Data connection already open; Transfer starting.
Ftp.dll Information: 0 :  8 11:16:58 Data connection established.
Ftp.dll Information: 0 :  8 11:16:58 S: 226 Transfer complete.
Ftp.dll Information: 0 :  8 11:16:59 C: QUIT
Ftp.dll Information: 0 :  8 11:16:59 S: 221 Bye
AArrggh we can close this topic!

It's working now:

  f.ActiveModeAddress = Dns.GetHostEntry(Dns.GetHostName())
        .AddressList
        .First(x => x.AddressFamily == AddressFamily.InterNetwork);
I'll definitely buy this now!

Thanks for your support, have a good weekend and thx for the great and helpful discussion
Hi,
unfortunately I found same issue again with Active
If u need user & password for testing let me know

Start --------------- 52.174.59.196 TEST Server Azure Cloud
Active mode 52.174.59.196 TEST Server Azure Cloud
Ftp.dll Information: 0 :  8 09:53:46 Connecting to '52.174.59.196:21', SSL: False.
Ftp.dll Information: 0 :  8 09:53:46 Control connection uses port: 58294 (227,182)
Ftp.dll Information: 0 :  8 09:53:46 S: 220-Microsoft FTP Service
Ftp.dll Information: 0 :  8 09:53:46 S: 220 Svenni FTP
Ftp.dll Information: 0 :  8 09:53:46 C: USER *****
Ftp.dll Information: 0 :  8 09:53:46 S: 331 Password required
Ftp.dll Information: 0 :  8 09:53:46 C: PASS ****
Ftp.dll Information: 0 :  8 09:53:46 S: 230-Welcome by Svenni FTP
Ftp.dll Information: 0 :  8 09:53:46 S: 230 User logged in.
Ftp.dll Information: 0 :  8 09:53:46 C: FEAT
Ftp.dll Information: 0 :  8 09:53:46 S: 211-Extended features supported:
Ftp.dll Information: 0 :  8 09:53:46 S:  LANG EN*
Ftp.dll Information: 0 :  8 09:53:46 S:  UTF8
Ftp.dll Information: 0 :  8 09:53:46 S:  AUTH TLS;TLS-C;SSL;TLS-P;
Ftp.dll Information: 0 :  8 09:53:46 S:  PBSZ
Ftp.dll Information: 0 :  8 09:53:46 S:  PROT C;P;
Ftp.dll Information: 0 :  8 09:53:46 S:  CCC
Ftp.dll Information: 0 :  8 09:53:46 S:  HOST
Ftp.dll Information: 0 :  8 09:53:46 S:  SIZE
Ftp.dll Information: 0 :  8 09:53:46 S:  MDTM
Ftp.dll Information: 0 :  8 09:53:46 S:  REST STREAM
Ftp.dll Information: 0 :  8 09:53:46 S: 211 END
Ftp.dll Information: 0 :  8 09:53:46 C: OPTS UTF8 ON
Ftp.dll Information: 0 :  8 09:53:46 S: 200 OPTS UTF8 command successful - UTF8 encoding now ON.
Ftp.dll Information: 0 :  8 09:53:46 C: TYPE A
Ftp.dll Information: 0 :  8 09:53:46 S: 200 Type set to A.
Ftp.dll Information: 0 :  8 09:53:46 Binding to: 10.218.6.48:0
Ftp.dll Information: 0 :  8 09:53:46 Bound to: 10.218.6.48:0
Ftp.dll Information: 0 :  8 09:53:46 C: PORT 10,218,6,48,227,183
Ftp.dll Information: 0 :  8 09:53:46 S: 200 PORT command successful.
Ftp.dll Information: 0 :  8 09:53:46 C: LIST
Ftp.dll Information: 0 :  8 09:53:46 S: 150 Opening ASCII mode data connection.
Ftp.dll Information: 0 :  8 09:54:16 Limilabs.FTP.Client.FtpException: Remote server has not initiated the connection to '10.218.6.48:58295'.
   at   . ()
   at   .GetSocket()
   at   .  (Action`1 action)
   at   . ​(Stream local)
   at Limilabs.FTP.Client.Ftp.<>c__DisplayClass112_0.<SendDownloadCommand>b__0()
   at Limilabs.FTP.Client.Ftp.  (    action)
Ftp.dll Information: 0 :  8 09:54:16 S: 550
Exception thrown: 'Limilabs.FTP.Client.FtpResponseException' in Ftp.dll
 52.174.59.196
Ftp.dll Information: 0 :  8 09:54:16 C: QUIT
Ftp.dll Information: 0 :  8 09:54:17 S: 221 Bye
------------------------
******************Fertig
this is the detailed log from FileZilla
Status:    Disconnected from server
Status:    Connecting to 52.174.59.196:21...
Status:    Connection established, waiting for welcome message...
Response:    220-Microsoft FTP Service
Response:    220 Svenni FTP
Command:    USER FTPUser
Response:    331 Password required
Command:    PASS ********
Response:    230-Welcome by Svenni FTP
Response:    230 User logged in.
Command:    OPTS UTF8 ON
Response:    200 OPTS UTF8 command successful - UTF8 encoding now ON.
Status:    Logged in
Status:    Retrieving directory listing...
Command:    PWD
Response:    257 "/" is current directory.
Status:    Directory listing of "/" successful
Please send us credentials via email.

The error says that the FTP server hasn't connected to your client machine for active mode data transfer.
...