Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: Ruudboy on August 25, 2003, 03:03:22 PM



Title: Help with do while not eof for ftp program
Post by: Ruudboy on August 25, 2003, 03:03:22 PM
i have this so far and want it to print the whole file from one variable.
any help would be useful. if your thinking it's abit strange then it's because it's for my ftp program


Code:
PRINT "Opening file"
OPEN "a:\test.bas" FOR INPUT AS #1
DO WHILE NOT EOF(1)
    INPUT #1, msg3$
    PRINT "test line: ";
    PRINT msg3$
LOOP
CLOSE #1


Title: Help with do while not eof for ftp program
Post by: whitetiger0990 on August 25, 2003, 04:01:35 PM
what do you need help on?


Title: Help with do while not eof for ftp program
Post by: oracle on August 25, 2003, 07:33:47 PM
You mean that you want the whole file contents as one variable? Well... you'll need to make a *big* string, and add CHR$(13) and CHR$(10) between the lines, like this: (untested)

Code:
PRINT "Opening file"
OPEN "a:\test.bas" FOR INPUT AS #1
DO WHILE NOT EOF(1)
    INPUT #1, currentline$
    wholefile$ = wholefile$ + CHR$(13) + CHR$(10) + currentline$
LOOP
CLOSE #1

PRINT "The whole file as one variable:"
PRINT: PRINT wholefile$


See what that does, and post any problems.


Title: Help with do while not eof for ftp program
Post by: na_th_an on August 25, 2003, 09:06:17 PM
This will only work for short files. QB string limitation ...


Title: Help with do while not eof for ftp program
Post by: Ruudboy on August 26, 2003, 02:07:05 PM
thanx for the help. how long is the string limitation.

because of this is there anyway of getting the code to reach the string limitation. then save the rest of the file to another string and so on.


Title: Help with do while not eof for ftp program
Post by: ak00ma on August 26, 2003, 02:27:54 PM
One string's maximum length = 32768 ASCIIs


Title: Help with do while not eof for ftp program
Post by: Ruudboy on August 27, 2003, 02:55:03 PM
i've just thought that i'll only be able to send text and ascii files. unless them 8mb ones you view which display about four characters mean somin


Title: Help with do while not eof for ftp program
Post by: oracle on August 27, 2003, 07:42:28 PM
You could save some in one string and some in the other, but before wasting so much memory, why do you need to have the contents of an entire file in a single variable? Post up here some psuedo code for your routine, and we can see if there is a better way.


Title: Help with do while not eof for ftp program
Post by: na_th_an on August 27, 2003, 11:30:53 PM
I have coded FTP servers in Unix minicomputers, and you sent "packets" of data. You opened the file, sent X characters, sent X characters, ... until you completed the file.  Your buffer shouldn't  be so big. In FTP protocol, frames have a max length that you have to take in account. So to make a big transfer you have to split files in many frames.


Title: Help with do while not eof for ftp program
Post by: ak00ma on August 28, 2003, 01:25:07 AM
You can use XMS. You  simply make something like a normal screen buffer with 1024x786 or so (804864 Bytes) with 8bits per pixel, so you can save one ASCII character per pixel.


Title: Help with do while not eof for ftp program
Post by: Ruudboy on August 28, 2003, 10:14:09 AM
my buffer is 256


Title: Help with do while not eof for ftp program
Post by: Neo on August 28, 2003, 10:45:41 AM
256 bytes? That's a whole lot smaller than what you first had :).

Ok, when I use buffers for fast file reading/writing I usually take buffers with size 1 to 4 kB, because the speed and the memory usage are balanced at that point.

But I'm thus suggesting this:

Code:
DEFINT A-Z

CONST BUFFERSIZE = 4096
CONST PACKET = 0
CONST STARTPACKET = PACKET + 1
CONST STOPPACKET = PACKET - 1

got& = 0

'Send a create-file command to server
SendFTP "ftp://Idontknow", "bla.BAS", STARTPACKET

OPEN "bla.BAS" FOR BINARY AS #1
   flen& = LOF(1)
   DO
      bufsiz = BUFFERSIZE
      IF got& + BUFFERSIZE > flen& THEN bufsiz = flen& - got&
      buffer$ = SPACE$(bufsiz)
      GET #1, , buffer$

      'send  a packet to ftp server
      SendFTP "ftp://Idontknow", buffer$, PACKET

      got& = got& + bufsiz
   LOOP UNTIL got& = flen&

   'tell the ftp server file is completed and can be closed
   SendFTP "ftp://Idontknow", "", STOPPACKET
CLOSE #1


Do you get that ;)?

Btw, SendFTP is a SUB-procedure you write yourself for handling the FTP-command and -protocol etc..


Title: Help with do while not eof for ftp program
Post by: Ruudboy on August 28, 2003, 02:43:56 PM
i don't think you get my ftp program do you. it is a straight link computer to computer.

like running laplink.


Title: Help with do while not eof for ftp program
Post by: Neo on September 01, 2003, 04:36:23 AM
Then I think you can use OUTs to send the messages to the port which the other computer is connected to. The other computer should be running a program then which reads the values transferred and put it back in a file.