Announcement

Collapse
No announcement yet.

Better way to detect EOF?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Better way to detect EOF?

    Hello all...

    I know this question is better suited for the Internet forum but I thought I would get quicker results from this forum due to its popularity.

    I have been writing a small FTP client and have encountered a problem reading the response messages in a reliable way from the server. After I have sent in the login information and have read what appears to be the END of the "login message", I would then send the PASV command. On some servers (particularly Microsoft FTP services), when I tried to read the response from the PASV command I ended up getting more "login message" data.

    Here is an example of what I mean:
    ----------------------------------

    tcp print hcmd, "USER anonymous"
    do until eof(hcmd)
    tcp line hcmd, buffer
    msgbox buffer
    loop

    tcp print hcmd, "PASS [email protected]"
    do until eof(hcmd)
    tcp line hcmd, buffer
    msgbox buffer
    loop

    tcp print hcmd, "PASV"
    do until eof(hcmd)
    tcp line hcmd, buffer
    msgbox buffer
    loop

    ** At this point, on some servers, there would still be some message data available from the previous command "PASS". I didnt think that this could be, because I used the "do until eof" to ensure that all the data sent would be read in. I have also tried to use "tcp recv, 65536, buffer" as a bulk read, but this ended up chopping the message up in little chunks. I have looked at the PBFTP example but that seems to rely on a specific string to exit the read loop.

    If someone could shed some light on this I would greatly appreciate it.

    Cheers!

  • #2
    I posted some ftp code a while back, I think it's at http://www.powerbasic.com/files/pub/inet/
    You might want to download it and have a look, it's pretty well commented and handles the login just fine.
    Best Regards,
    Don

    ------------------
    Don Dickinson
    www.greatwebdivide.com

    Comment


    • #3
      The following the is best way to detect the end of the data stream... it is more reliable than using EOF() as EOF() may trigger before the data stream has been completely received.
      Code:
          LOCAL buffer AS STRING
          LOCAL Iserv  AS STRING
      ...
          DO
            TCP RECV #1, 32767, buffer$
            Iserv$ = Iserv$ + buffer$
          LOOP WHILE LEN(buffer)
      ...

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Lance:

        " ... as EOF() may trigger before the data stream has been
        completely received."

        Is it really true ?

        Other:
        DO
        TCP RECV #1, 32767, buffer$
        Iserv$ = Iserv$ + buffer$
        LOOP WHILE LEN(buffer) OR ISTRUE(ERR)

        In very fast machines does LEN(buffer)=0 but other byte is
        getting ?

        Is it a better solution ?
        DO
        TCP RECV #1, 32767, buffer$
        SLEEP 1
        Iserv$ = Iserv$ + buffer$
        LOOP WHILE LEN(buffer) OR ISTRUE(ERR)

        Thanks.

        Comment

        Working...
        X