0 votes
by (120 points)
edited

I am running code as a windows service. When I run the same code in debug mode it works, when i run the code as a service I get the error "Cannot read from a directory ('/')". I narrowed the command down to FTP.GetFiles method. In the FTP directory there are 81 files with the largest being 110k in size. I have used the rebex.filelogwriter with the log level set to debug. I have tried using pasv mode and active mode but receive the same error. Here is the Rebex Log. I have removed the user and ipaddress from the file. Thank you for any help you can provide.

2010-21-06 08:10:01.046 Opening log file.
2010-21-06 08:10:01.046 INFO Ftp(2) Info: Connecting to ##FTP:PORT## using Ftp 3.0.3588.0.
2010-21-06 08:10:01.046 INFO Ftp(2) Info: Using proxy none.
2010-21-06 08:10:01.234 DEBUG Ftp(2) Info: Connection succeeded.
2010-21-06 08:10:01.437 INFO Ftp(2) Response: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
2010-21-06 08:10:01.437 INFO Ftp(2) Response: 220-You are user number 5 of 250 allowed.
2010-21-06 08:10:01.437 INFO Ftp(2) Response: 220-<<
2010-21-06 08:10:01.437 INFO Ftp(2) Command: FEAT
2010-21-06 08:10:01.640 INFO Ftp(2) Response: 211-Extensions supported:
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  EPRT
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  IDLE
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  MDTM
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  SIZE
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  REST STREAM
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  MLSD
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  ESTP
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  PASV
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  EPSV
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  SPSV
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  ESTA
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  AUTH TLS
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  PBSZ
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  PROT
2010-21-06 08:10:01.640 INFO Ftp(2) Response:  UTF8
2010-21-06 08:10:01.640 INFO Ftp(2) Response: 211 End.
2010-21-06 08:10:01.640 INFO Ftp(2) Command: USER ##
2010-21-06 08:10:01.828 INFO Ftp(2) Response: 331 User ## OK. Password required
2010-21-06 08:10:01.828 INFO Ftp(2) Command: PASS **********
2010-21-06 08:10:02.031 INFO Ftp(2) Response: 230-Your bandwidth usage is restricted
2010-21-06 08:10:02.031 INFO Ftp(2) Response: 230-User ## has group access to:  ftpgroup
2010-21-06 08:10:02.031 INFO Ftp(2) Response: 230 OK. Current restricted directory is /
2010-21-06 08:10:02.031 INFO Ftp(2) Command: OPTS UTF8 ON
2010-21-06 08:10:02.234 INFO Ftp(2) Response: 200 OK, UTF-8 enabled
2010-21-06 08:10:02.234 DEBUG Ftp(2) Info: Starting data transfer.
2010-21-06 08:10:02.234 INFO Ftp(2) Command: TYPE I
2010-21-06 08:10:02.625 INFO Ftp(2) Response: 200 TYPE is now 8-bit binary
2010-21-06 08:10:02.625 INFO Ftp(2) Command: PASV
2010-21-06 08:10:02.828 INFO Ftp(2) Response: 227 Entering Passive Mode (##IPADDRESS##)
2010-21-06 08:10:02.828 DEBUG Ftp(2) Info: Establishing data connection to ##IPADDRESS##.
2010-21-06 08:10:23.859 DEBUG Ftp(2) Info: Error while starting data transfer: Rebex.Net.FtpException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> Rebex.Net.ProxySocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> Rebex.Net.ProxySocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at 328075837.13357030529.151169660(String , IPAddress , Int32 )
   --- End of inner exception stack trace ---
   at 328075837.13357030529.151169660(String , IPAddress , Int32 )
   --- End of inner exception stack trace ---
   at 328075837.13357030529.362804169(IAsyncResult , String )
   at 328075837.13357030529.15613119759(IAsyncResult , Int32 )
   at Rebex.Net.ProxySocket.EndConnect(IAsyncResult asyncResult)
   at 328075837.588172452.151169660(EndPoint )
   --- End of inner exception stack trace ---
   at 328075837.588172452.151169660(EndPoint )
   at Rebex.Net.Ftp.19941338139(String , 588172452 , Int64 , FtpTransferState )
2010-21-06 08:10:23.859 DEBUG Ftp(2) Info: Closing data connection.
2010-21-06 08:10:23.859 ERROR Ftp(2) Info: Rebex.Net.FtpBatchTransferException: Cannot read from a directory ('/'). ---> Rebex.Net.FtpException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> Rebex.Net.ProxySocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> Rebex.Net.ProxySocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at 328075837.13357030529.151169660(String , IPAddress , Int32 )
   --- End of inner exception stack trace ---
   at 328075837.13357030529.151169660(String , IPAddress , Int32 )
   --- End of inner exception stack trace ---
   at 328075837.13357030529.362804169(IAsyncResult , String )
   at 328075837.13357030529.15613119759(IAsyncResult , Int32 )
   at Rebex.Net.ProxySocket.EndConnect(IAsyncResult asyncResult)
   at 328075837.588172452.151169660(EndPoint )
   --- End of inner exception stack trace ---
   at 328075837.588172452.151169660(EndPoint )
   at Rebex.Net.Ftp.19941338139(String , 588172452 , Int64 , FtpTransferState )
   at Rebex.Net.Ftp.8956377289(String , Stream , Int64 )
   at Rebex.Net.Ftp.GetList(String arguments)
   at 328075837.20961014519.1569771334(String )
   at 328075837.20961014519.AppendRemoteFileList(ArrayList dirs, ArrayList files, 792810434 remotePathDesc, Regex nameFilter, Boolean appendDirs, String remotePath, String localPath)
   at 328075837.17759126019.17005970309(792810434 )
   --- End of inner exception stack trace ---
   at 328075837.17759126019.HandleException(Exception ex, 2061242560 type, String remotePath, String localPath, 2074704321 remoteInfo, 2074704321 localInfo, 16902977159 defaultAction, 16902977159 possibleActions, 16902977159& chosenAction)
   at 328075837.17759126019.HandleCaughtException(Exception caught, String message, 2061242560 type, String remotePath, String localPath, 2074704321 remoteInfo, 2074704321 localInfo, 16902977159 possibleActions, 16902977159& chosenAction)
   at 328075837.17759126019.17005970309(792810434 )
   at 328075837.17759126019.5474409839(String , String )
   at 328075837.17759126019.TransferFiles(Boolean putFile, Object expectedRootItem, String localPath, String remotePath, 1286277555 transferOptions, 2117658205 existingFileMode)
   at Rebex.Net.Ftp.GetFiles(String remotePath, String localDirectoryPath, FtpBatchTransferOptions transferOptions, FtpActionOnExistingFiles existingFileMode)
2010-21-06 08:10:23.859
Applies to: Rebex FTP/SSL
by (147k points)
I changed the formatting of the log to make it a bit more readable.

2 Answers

0 votes
by (147k points)
edited

The topmost exception message is misleading (this will be fixed for the next release) - what happened is that the connection attempt failed while establishing a data connection.

In FTP's passive mode, data connection is established by connecting to the IP address/port specified by the server in response to PASV command. Sometimes, misconfigured FTP servers or firewalls transmit a different IP address than desired (for example, an IP address in FTP server's local network), which makes the process of establishing the data connection somewhat complicated.

Rebex FTP has a built-in workaround for this issue, but perhaps it was not applied in this case for some reason (hard to tell with no knowledge of your IP addresses). Try explicitly forcing this workaround using the following FTP option:

C#:

ftp.Options |= FtpOptions.IgnorePassiveModeAddress;

VB.NET

ftp.Options = Ftp.Options Or FtpOptions.IgnorePassiveModeAddress

(where "ftp" is an instance of Ftp object)


If this doesn't help, try enabling one more option:

C#:

ftp.Options |= FtpOptions.ConnectPassiveLater;

VB.NET

ftp.Options = Ftp.Options Or FtpOptions.ConnectPassiveLater;

This changes the method of establishing the data connection slightly - it causes it to be initialized only after the LIST/NLST/RETR/STOR command has been sent.


If none of this helps - are you able to connect using any third-party FTP client, such as FileZilla? If you are, please send us its communication log to support@rebex.net, we should be able to tell what it did differently and provide instructions for reproducing the same behavior with Rebex FTP.

0 votes
by (140 points)
edited

I am getting the above error for one of the FTP sites which I am trying to connect. It works fine using Filezilla:

Status: Resolving address of trade.marketplace.buy.com
Status: Connecting to 209.67.181.90:21...
Status: Connection established, waiting for welcome message...
Response:   220 Marketplace ready...
Command:    USER xxx@steinersports.com
Response:   331 Password required for xxx@steinersports.com.
Command:    PASS ****
Response:   230 User xxx@steinersports.com logged in.
Command:    CLNT FileZilla
Response:   200 Noted.
Command:    OPTS UTF8 ON
Response:   200 UTF8 OPTS ON
Status: Connected
Status: Retrieving directory listing...
Command:    PWD
Response:   257 "/" is current directory.
Status: Directory listing successful

by (18.0k points)
edited

Please, first try the hints mentioned by Lukas above. Just note, that the ftp.Options property has been refactored to several separate bool properties in the Settings object(ftp.Settings.IgnorePassiveModeAddress, ftp.Settings.ConnectPassiveLater).

If it does not help, please send us a log from the Rebex FTP component (according to this article)

...