Quantcast
Channel: Alex FTPS Client
Viewing all articles
Browse latest Browse all 114

Created Unassigned: Feature list not trimmed (many symptoms possible) [9526]

$
0
0
My symptom:
__ERROR: The handshake failed due to an unexpected packet format.__

Using an Implicit FTP connection. It worked with Filezilla client.
By comparing the filezilla client output and my code, I fixed my problem by issuing 2 further commands:
FTPReply reply1 = client.SendCustomCommand("PBSZ 0");
FTPReply reply2 = client.SendCustomCommand("PROT P");

But then found on this forum that this has already been addressed in this patch:
https://ftps.codeplex.com/SourceControl/changeset/74297
from a discussion here:
https://ftps.codeplex.com/discussions/349204

Turns out my problem lies with feature listing.

FTPSClient.cs:

```
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;
}
```

The customer ftp server is now returning this to me:

```
Extensions supported:
EPSV
MDTM
PASV
REST STREAM
SIZE
UTF8
PBSZ
PROT
X-NOVELLABS
X-CITRIX
End.
```

Note the leading space!

In my case, this means FeatCmd() ends up returning features like " PBSZ" (with leading space) and " PROT" (with leading space). And the code in SslDataChannelImplicitEncryptionRequest which call:
```
CheckFeature("PBSZ") && CheckFeature("PROT")
```
doesn't get run!

I imagine many symptoms are possible, anything that calls CheckFeature and if the server returns a list of features with trailing spaces.

My fix is to add this line:
```
for (int i = 0; i < features.Count; i++) features[i] = features[i].Trim();
```
in method FeatCmd() in FTPSClient.cs, full method becomes:
```
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);
for (int i = 0; i < features.Count; i++) features[i] = features[i].Trim();
return features;
}
```

Although I'm a bit confused why this has suddenly appeared on my customer's ftp server. Searching the web, I found that the FEAT command must include the leading space:
https://tools.ietf.org/html/rfc3659#section-3.3

Viewing all articles
Browse latest Browse all 114

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>