This project is read-only.

ArgumentOutOfRangeException in FTPSClient.FeatCmd()

Jun 9, 2012 at 8:28 PM
Edited Jun 9, 2012 at 8:29 PM

Hello,

I use your great library in my editor for channel lists of satellite receivers. It works really good, but when connecting to the ftp-server on the Kathrein UFS925 satellite receiver, I get an exception in FTPSClient.FeatCmd().

The RemoveAt() call in the method causes an ArgumentOutOfRangeException. Maybe you can add some safety checks if the List is null or if there are entries in the list, before calling the RemoveAt() ?

 

Anyways, thanks for the great library!

 

Best Regards

Bernd

Jun 12, 2012 at 11:52 AM

Hi,

can you please post an example in order to reproduce the error?

 

Thanks,

Alessandro

Jun 12, 2012 at 5:47 PM

Hello,

the problem only occurs when you connect to the ftp server on the Kathrein UFS925 satellite receiver. Maybe the ftp-server on the UFS925 is doing something wrong, but the ftps library should not crash.

I cannot post an example. The problem occurs when connecting to the ftp-server.

The call stack looks this:

 

Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index

at System.ThrowHelper.ThrowArgumentOutOfRangeException()

at System.Collections.Generic.List'1.RemoveAt(Int32 index)

at AllexPilotti.FTPS.Client.FTPSClient.FeatCmd()

at AllexPilotti.FTPS.Client.FTPSClient.GetFeatureFromServer()

at AllexPilotti.FTPS.Client.FTPSClient.Connect(String hostname, Int32 port, NetworkCredential credential, ESSLSupportMode sslSupportMode, RemoteCertificateValidationCallback userValidateServerCertificate, X509Certificate x509ClientCert, Int32 sslMinKeyExchangeAlgStrength, Int32 sslMinCipherAlgStrength, Int32 sslMinHashAlgStrength, Nullable'1 timeout, Boolean useCtrlEndPointAddressForData, EDataConnectionMode dataConnectionMode)

 

Best Regards

Bernd

Jun 12, 2012 at 5:53 PM

Hi Bernd,

I agree that it should not crash, but I need to replicate the issue in order to solve it :-)

Is the ftp server you are accessing public in case can you please post your code / commnd line sample?

 

Thanks,

Alessandro 

Jun 13, 2012 at 7:00 PM

The ftp server is closed source.

I don't have the satellite receiver so I also cannot reproduce the error. I just got a screenshot from a guy who uses my program to connect to the satellite receiver.

Then I had a look at your code and saw the method FeatCmd() and where it could crash:

private IList<string> FeatCmd()
{
    FTPReply reply = HandleCmd("FEAT");
    IList<string> features = new List<string>(reply.Message.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
    features.RemoveAt(0);
    features.RemoveAt(features.Count - 1);

    return features;
}

 

I thought you can change it to that:

private IList<string> FeatCmd()
{
    FTPReply reply = HandleCmd("FEAT");
    IList<string> features = new List<string>(reply.Message.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
   
    if(features != null)
    {
        if(features.Count > 0)
            features.RemoveAt(0);
       
        if(features.Count > 0)
            features.RemoveAt(features.Count - 1);
    }
   
    return features;
}

 

Is it not that easy?

 

Regards

Bernd

Jun 13, 2012 at 7:08 PM

"features" will never be null in your code.

Can you get a log of the communication? You can get it with the library, with FileZilla , etc.

Beside that, you  don't have to ask to patch the code. It's open source, you can do it, test it and if it works we can update the code for the next release :-)

 

Best,

Alessandro

Jun 15, 2012 at 3:45 PM

I do have a log of Filezilla:

 

Status: Verbinde mit 192.168.xxx.xxx:2121...
Status: Verbindung hergestellt, warte auf Willkommensnachricht...
Antwort: 220 Service ready for new user
Befehl: USER anonymus
Antwort: 331 User name okay, need password
Befehl: PASS ****
Antwort: 230 User logged in, proceed. Logged out if appropriate
Befehl: SYST
Antwort: 230 User logged in, proceed. Logged out if appropriate
Befehl: FEAT
Antwort: 215 UNIX system type
Status: Verbunden
Status: Empfange Verzeichnisinhalt...
Befehl: PWD
Antwort: 257 "/ftproot/" is your current location
Befehl: TYPE I
Antwort: 200 Command okay
Befehl: PASV
Antwort: 227 Entering Passive Mode (192,168,xxx,xxx,200,222)
Befehl: LIST
Antwort: 150 File status okay; about to open data connection
Antwort: 226 Closing data connection

 

I will build a new version with the changed code and let some people test it. Thx for your help! :-)

Jun 15, 2012 at 3:50 PM

Yes, the FEAT list is empty.

Your code should do the trick:

 if(features.Count > 0)
            features.RemoveAt(0);
        
 if(features.Count > 0)
            features.RemoveAt(features.Count - 1);

Jun 15, 2012 at 3:53 PM
Edited Jun 16, 2012 at 6:30 AM

I just noticed that the log is strange.

215 UNIX system type

should be the answer for SYST and not for FEAT.

 

 

I just tested with my Kathrein UFS912 and it gave me this output:

Befehl:    SYST
Antwort:    215 UNIX system type
Befehl:    FEAT
Antwort:    502 Command not implemented

 

I can connect to my UFS912 with the ftps library, but the UFS925 causes the exception. Strange!

 

Regards

Bernd

 

edit: I got the feedback that the exception is solved, but now there is a different exception

Callstack:

Command not implemented

at AlexPilotti.FTPS.Client.FTPSClient.GetReply()

at AlexPilotti.FTPS.Client.FTPSClient.HandleCmd(string command, Boolean waitForAnswer)

at AlexPilotti.FTPS.Client.FTPSClient.TypeCmd(ERepType repType, string param2)

at AlexPilotti.FTPS.Client.FTPSClient.Connect(...)

 

:-(