Checking if a Transfer is Active

Use the IsPending property to determine whether a transfer is active or if it is already finished with success or error. This can be useful in combination with async commands or during an interactive script. The IsPending property will return a value of either true or false.

Syntax

Boolean Object.IsPending(long taskIdx)

 

Parameter

TaskIdx

This is a task index in the array of tasks created by the various asynchronous methods. [0.. AsyncTaskNumber minus one, or - 1 (last asynchronous task started)]

This has a default value (if nothing is specified) of ALL tasks. Therefore, IsPending will return true if any task is still pending. It will return false if none are pending.

Example 1

Set MySite = CreateObject("CuteFTPPro.TEConnection")

'Regular connection code here:

MySite.Download inbound/*.*", "c:\temp"

If CBool(MySite.IsPending) Then

MsgBox "task is in working state" + MySite.Host

End if

Example 2

Here is another example that checks an asynchronous transfer and will return various transfer progress properties of each transfer while IsPending is true.

If you copy and paste this code, be aware that line breaks may be inserted into the code.

 

Set MySite = CreateObject("CuteFTPPro.TEConnection")

MySite.Protocol = "FTP"

MySite.Port = "21"

MySite.Host = "ftp.url"

MySite.login = "loginname"

MySite.Password = "your pass"

MySite.Connect

MySite.Option("CleanupAsync") = False

' line break

strNL = (Chr(13) & Chr(10))

MySite.MaxConnections = 3

MySite.Option("ThrowError") = false

MySite.DownloadAsync "inbound/*.*", "c:\temp"

bContinue = true

while CBool(MySite.IsPending) and bContinue

str = "LOOP, Total: " & MySite.AsyncTaskNumber & strNL

for i = 0 to MySite.AsyncTaskNumber - 1 step 1

str = str & i & ": size: " & MySite.TransferredSize(i) & ", speed: " & MySite.Speed(i) & ", time left: " & MySite.TimeLeft(i) & ", status: " & MySite.Status(i) & strNL

next

str = str & "YES - continue loop, NO - stop tasks, CANCEL - exit loop"

nUserChoise = MsgBox(str, vbYesNocancel) 'press YES many time to see transfer progresses

if nUserChoise = vbCancel then

bContinue = false

elseif nUserChoise = vbNO then

MySite.AbortAsync 'abort all tasks

bContinue = false

end if

wend

str = "DONE, Total: " & MySite.AsyncTaskNumber & strNL

for i = 0 to MySite.AsyncTaskNumber - 1 step 1

str = str & i & ": size: " & MySite.TransferredSize(i) & ", speed: " & MySite.Speed(i) & ", time left: " & MySite.TimeLeft(i) & ", status: " & MySite.Status(i) & strNL

next

MsgBox str