Jump to content

Jump one step back inside a loop

Recommended Posts

I want to do an ftp session to a remote machine, getting a number of files, move on to the next machine... The code for doing this will be the same for every machine, so naturally I will put this inside a loop because the only thing changed is the ftp script I call.

If anything goes wrong I want to restart this ftp session and try again. But I don

Link to comment

This is the code I am working on. A state machine with 2 states. Both of them do exactly the same:

1 Delete all files from a certain directory

2 Run an FTP script to fetch new files into this directory

3 Checks whether the filenames meet certain string patterns.

If something goes wrong, the third process will generate a false and the same case should be run again.

In the end I have to do this for 6 machines. Because the code is exactly the same I want to put this inside a loop, but then if number 3 goes wrong I have to FTP all over again. That would be most inconvenient.

Download File:post-4151-1153228842.zip

Link to comment

I'm not sure I've completely understood what you're trying to do here, but here's my suggestion:

Don't use a state machine. Instead, create an array of clusters and store that in a shift register in the while loop. Inside the while loop, remove the first element of the array, which should be a cluster containing the name of the remote FTP server, the directory, and list of file names. Run your code for that loop. If it succeeds, continue to the next element of the array; if it fails, add that cluster back into the array and try again. See the attached image.

Also note that I disconnected the error shift register inside the while loop. Be careful with storing errors in a shift register; the way you had written it previously, if one case caused an error, that error would continue through the rest of the cases, probably causing them not to do anything.


Link to comment

Many thanks, this should work indeed. I will try this out tommorrow.

The reason for storing the errors inside the shift register is that I want to do a lot more and some processes will go wrong if there is any failure (others will work allright). Some of my subvis will be inside a case structure (error does nothing, no error the process starts). Others will run anyway regardless if there are failures or not.

It works fine!! :D

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.