Inet bug when FTPing files

LenkaL
LenkaL used Ask the Experts™
on
Hello guys!
 
 I use Inet functionality when connecting to server and
 FTPing files back and forth using VB.
 
 It works fine, does everything when I execute lines of my
 code one by one - using F8.
 However when I execute the whole code (F5) it gives me
 an error message:
 Run-time Error #35764
 "Still executing last request"

 I'm using this code:
 ----------------------------------------------------
 Private Sub OkB_Click()

 Dim sFileList As String
 Dim sBuff     As String
  Inet1.URL = "ftp://153......"
  Inet1.UserName = "me"
  Inet1.Password = "me"
   
  Inet1.Execute , "Get Myfile.txt C:\temp\Myfile.txt "

  Inet1.Execute , "DIR"

  Do
     sBuff = Inet1.GetChunk(1024)
     sFileList = sFileList & sBuff
  Loop Until Len(sBuff) = 0
  MsgBox sFileList
 
  Inet1.Execute , "CLOSE" ' Close the connection.
End Sub
-------------------------------------------------------
 
 Again, it works perfect when debugging (F8) and
 gives an error message above, when F5 is pressed on the line:
 Inet1.Execute , "Get Myfile.txt C:\temp\Myfile.txt "

 In MSDN they hint on some workaround but very vaguely.
 Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
At the very least, you should check to see if it is still executing before moving on to the next command.

Inet1.Execute , "Get Myfile.txt C:\temp\Myfile.txt "

Do While Inet1.StillExecuting
  DoEvents
Loop

 Inet1.Execute , "DIR"
The Do while loop should be put after every command executed on the server.


A better way to do this is to put code in the StateChanged event of the control to handle the transfer of data.

Here is a good example of that in a full FTP client:

http://www.planetsourcecode.com/xq/ASP/txtCodeId.5675/lngWId.1/qx/vb/scripts/ShowCode.htm

Author

Commented:

 Thanks, that does it.
 Have a small question on that subject, didn't want
 to put it as a separate question, but will increase the
 points.
 -----------
 Now I'm getting the Chunk of data into a message box.
 How do I get this data into a List Box on my form or into
 a text file - C:\Temp\Files.txt?
 That's what I use now (as above):

 Do
    sBuff = Inet1.GetChunk(1024)
    sFileList = sFileList & sBuff
 Loop Until Len(sBuff) = 0
 MsgBox sFileList
 ------------
 lbFiles is my List Box, I do AddItem but the record comes
 out funky, all in one line.
 Text file is Files.txt I want to clear it and put new
 data in.

 Thanks.
 
 
 
Commented:
This will work in VB 6.0

    'In the declarations for this sub..
    Dim sFileList As String
    Dim sFileArr() As String
    Dim i As Integer
    ....
   
    'MsgBox sFileList
    sFileArr = Split(sFileList, vbCrLf)  'If this is not working, try vbLf or vbCr.
    For i = LBound(sFileArr) To UBound(sFileArr)
        list1.AddItem sFileArr(i)
    Next i
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:

 Perfect, man.
 Good solution, I got it also myself but used LEN and MID
 functions, which is much more complicated.
 
 Can you, please, put here the same for the text file,
 if it's not much a bother.
 

Commented:
>>but will increase the
points.

??

Author

Commented:

 Will put another question "For PaulHews" with 25 points?

Commented:
>Can you, please, put here the same for the text file,
if it's not much a bother.

What do you mean about hte text file?

Commented:
Oh, to write the same string into a text file:

Dim hFile as integer

...
'MsgBox sFileList


hFile = Freefile
Open "C:\Temp\dir.txt" For Binary Access Write as #hFile
Put #hFile,,sFileList
Close #hFile

Commented:
>>Will put another question "For PaulHews" with 25 points?

That sounds good to me.  :)

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial