RagingGoblin Posted July 18, 2006 Report Share Posted July 18, 2006 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 Quote Link to comment
crelf Posted July 18, 2006 Report Share Posted July 18, 2006 Please post an example of what you've already treid so we can make suggestions... Quote Link to comment
RagingGoblin Posted July 18, 2006 Author Report Share Posted July 18, 2006 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 Quote Link to comment
ned Posted July 18, 2006 Report Share Posted July 18, 2006 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. Quote Link to comment
RagingGoblin Posted July 18, 2006 Author Report Share Posted July 18, 2006 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!! Quote Link to comment
lavezza Posted July 20, 2006 Report Share Posted July 20, 2006 Here's my solution. Using a state machine give you that ability to add additional states fairly easily (like the Update Status state I added after I was finished) or redo a state (maybe you want to ask the user what to do if the Delete Files state fails) Pat Download File:post-192-1153361997.zip Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.