Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

download multiple files using FTP 1

Status
Not open for further replies.

nkyeshi01

Programmer
Nov 4, 2004
29
US
Hi to all,

ok, I'm trying to download several files,when I run the process step by step (F8) it works like a charm, but when I run it all at once I get the error message => Error:Still executing last request.

This ocurrs because after I login(logon function) to the server and change to another directory(inet1.execute, "CD directory) when I try to do a DIR (inet1.execute, "DIR ")so I can get the files that are in that directory ( vtData = frmExplore.Inet1.GetChunk(1024, icString) ) the error jumps out.

I have confirm that if I take out the DIR instruction (inet1.execute, "DIR ") the error is corrected ,but GETCHUNK does not get the files.


what can I do???? Should I apply the mget or VB6 does not support it

Thank you all

This is the code :



========= this function is to login to the server =========

Public Sub logon() 'ByVal choice As Integer)
On Error GoTo LogOnError
.
.
.

frmExplore.Inet1.Protocol = icFTP
frmExplore.Inet1.URL = address1
If usName1 = "" Then
frmExplore.Inet1.UserName = "anonymous"
Else
frmExplore.Inet1.UserName = usName1
End If
frmExplore.Inet1.Password = Passwd1
frmExplore.Inet1.Execute , "DIR"
Exit Sub
LogOnError:
If Err = 35754 Then
MsgBox "Cannot connect to the remote host"
Else
MsgBox Err.Description
End If
frmExplore.Inet1.cancel
End Sub



'============= check if the INET is READY =============
Public Function inetReady(Message As Boolean) As Boolean

On Error GoTo errhandler
Dim msg As String
Dim i As Long

Do While frmExplore.Inet1.StillExecuting = True
DoEvents
Loop
inetReady = True
Exit Function
errhandler:
MsgBox Err.Source & " " & Err.Number & " " & Err.Description
End Function


================== to execute the command ================
Public Sub SendCommand(ByVal cmd As String)
'envia el comando al server del FTP
On Error GoTo SendCommandErr
frmExplore.Inet1.Execute , cmd
Exit Sub
SendCommandErr:
MsgBox "Error: " & Err.Description
Resume Next
End Sub


============== to download the files ===================
Public Sub loadreports(ByVal direccione As String)
.
.
.


'change to outbond directory
Dim varr As String
varr = "CD outbound"
If inetReady(True) Then
Call SendCommand(varr)
End If


**********************************
'update the directory *
frmExplore.Inet1.Execute , "DIR" *
**********************************

'get list of the files in that directory
vtData = frmExplore.Inet1.GetChunk(1024, icString)
DoEvents

'Get all Information, pass it to a compatible variable
Do While Not bDone
strData = strData & vtData
If Len(vtData) <> 0 Then
bDone = True
End If
Loop

'keep the name of the existent files in an array
lsItems = Split(strData, vbCrLf)
For z = 0 To UBound(lsItems)
lsItem = Trim$(lsItems(z))
If lsItem <> "" Then
If Right$(lsItem, 1) <> "/" Then
loadarray(j) = lsItem
j = j + 1
Else
End If
End If
Next

'download the files
Do While loadarray(i) <> ""
var = loadarray(i)
cmd = "GET " & var & " " & direccion & var
If inetReady(True) Then
Call SendCommand(cmd)
End If
i = i + 1
Loop

'close the conection
varr = "CLOSE "
If inetReady(True) Then
Call SendCommand(varr)
End If

'erase the encrypted and leave the originals
i = 1
Dim name As String
Do While loadarray(i) <> ""
name = loadarray(i)
datain = direccion & name
var2 = Len(name) - 4
resul = Left(name, var2)
dataout = direccion & resul
Call fso.DecryptFile(pubkeyring, privkeyring, datain, dataout, passwd)
fso2.DeleteFile datain, True
i = i + 1
Loop

Exit Sub
GetRemoteFileErr:
MsgBox "Error: " & Err.Description
Resume Next
End Sub
 
Wow! That's a lot of code to do what you want to do. Here is a suggestion...

In your "Call SendCommand(cmd)" sub, you need to put the following loop directly after you request the file

Do until Inet1.StillExecuting = False
DoEvents
loop

This little tidbit of code will ensure that your file is downloaded fully before moving on to the next file. The reason it works in the step-by-step mode is because you are probably allowing enough time for the file to download before you move on to the next line of code.

Take care...

LF


"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 

LF,
Thanks a million dude, it worked just fine.
 
Hey, no problem. Thanks for the star!

LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top