Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix multiline response #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brushbox
Copy link

@brushbox brushbox commented Aug 9, 2019

I'm a bit of a Haskell n00b - this is my first PR.

I was trying to use ftp-client to look at ftp.bom.gov.au but it was failing on the welcome message. It seemed to not read the entire message. This small change fixed that problem. I'm not sure if it is a broadly valid solution (I suspect it might fail on a line that contains only the status code and no other chars). Not sure how to test that.

I would write some tests...but I haven't gotten that far with Haskell yet.

@mr
Copy link
Owner

mr commented Oct 11, 2019

So I've been checking out the FTP RFC and I'm not sure this change makes sense.
https://tools.ietf.org/html/rfc959#page-35

         Thus the format for multi-line replies is that the first line
         will begin with the exact required reply code, followed
         immediately by a Hyphen, "-" (also known as Minus), followed by
         text.  The last line will begin with the same code, followed
         immediately by Space <SP>, optionally some text, and the Telnet
         end-of-line code.

            For example:
                                123-First line
                                Second line
                                  234 A line beginning with numbers
                                123 The last line

Which seems to imply that only the first line uses the '-' character to indicate multiline. Since that is already consumed before this function is called, I don't think it needs to be checked. Can you show the output that you received? Maybe I'm not interpreting this correctly or they are doing something nonstandard.

@brushbox
Copy link
Author

brushbox commented Oct 16, 2019

Yeah...not the right fix for the general case. It would solve the data I was getting from bom.gov.au. The message was something like:

420- Blah
420- Blah
420- Blah
420- Blah
420- Blah
420- Blah
420 

So what we should look for is <code><space> rather than <code><not-a-dash> for the final line.

@kenranunderscore
Copy link

kenranunderscore commented Mar 30, 2020

Check out https://stackoverflow.com/questions/15820936/how-do-ftp-replies-work, especially the comment below the question. It is common for FTP servers to format multiline messages this way, even if that's not in accordance with the original RFC.

I stumbled over this when I got a FileZilla response that was formatted this way. I was actually in the process of doing a PR for this when I found this one :) @brushbox You should probably implement it the way you mentioned (stop when code repeats and the next character is a space). I added a test for that as well in my fork.

@mr
Copy link
Owner

mr commented Jun 16, 2020

I've tried to make this work in the general case here: #21

Still have to write some tests, but I'd like someone to confirm this works. I don't have access to a server that behaves this way, so if someone could test it themselves, or provide me a way to do it myself then I can consider merging my solution and closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants