views:

54

answers:

2

How can I wait the end of an ftp transfer on my iPhone app, if I have to do many ftp transfers in sequence?

I call the same method to make the transfers, changing the name of file.

[Ftp receiveFtp:file1]; [Ftp receiveFtp:file2]; [Ftp receiveFtp:file3];

Here, for example, I should wait the end of the first method before calling the second. Any ideas?

Thanks, Andrea

+1  A: 

I guess Ftp is doing its work on another thread, or you would not ask how to wait for a method to terminate to execute it's follower ?

if that assumption is true, then I suggest you make a protocol method that will tell to your delegate (your parent class) that the ftp transfer has finished, which will start the following file.

TheSquad
"or you would not ask how to wait for a method to terminate to execute it's follower" how do you mean?
Andrea Mattiuz
Andrea Mattiuz: A message isn't normally asynchronous; whatever you have after the message will only execute after the message returns. If `receiveFtp:` works synchronously (that is, receives the whole file before returning), then there would be no need to do anything special to wait for one file before trying to receive the next. Your question implies that `receiveFtp:` works **a**synchronously—that is, starts receiving the file in the background and then returns without waiting for that to finish. Hence the solution: Get `Ftp` to tell you when it finishes.
Peter Hosey
Peter Hosey: you give me the right way to solve the problem. Thanks
Andrea Mattiuz
A: 

Put all your filenames in a collection (i.e. NSMutableArray), and in your handler for a completed download, pop the next one from the array and start the next download as long as the list isn't empty.

Eiko
How can I know when the download is finished?
Andrea Mattiuz
Probably because some delegate method is called.
Eiko