ftp automation

ScriptFTP

The professional tool to automate FTP, SFTP, FTPS and schedule FTP batch jobs

The forum is now read only. Please, go to the the main ScriptFTP website if you need help.
Need help writing a script? Have any question about ScriptFTP?
Hi guys,
I've searched the forums (and if I have missed it then very sorry) but I can't find the answer to this.
I would like to create a while loop which for each iteration uses a different variable based on that iteration number.

For example :
FTP Script
  1. $display0="ready"
  2. $display1="steady"
  3. $display2="go"
  4. $display3="stop"
  5. $i=0
  6. WHILE($i<4)
  7.     Command such as PRINT or EXEC($display(current Si number))
  8. $i=$i+1
What I want it to do is to use the $i number to call a different variable based on the counter within the WHILE statement.
Can this be done, and can you please tell me how?
Again If I have overlooked the answer in the forum, please point me in the right direction.
Thank you,
Farhad
Hi Farhad,

Thanks for posting this question. Yes, it is something that I think is not covered in the forum.

You have to use ScriptFTP lists. Take a look at this example:
FTP Script
  1. $list = "|ready|steady|go|stop"
  2.  
  3. FOREACH $item in $list
  4.     PRINT($item)
A list is just a text string with a "|" before every item: |item1|item2|item3.... and so on
Hi,
Is there any other way to perform this as my script is slightly more complicated and I wanted to use different variables for different parts of the script?

So for example and in non-code terms,
FTP Script
  1. $Server1="ftp.site1"
  2. $Server2="ftp.site2"
  3. $Server3="ftp.site3"
  4. $file1="file1"
  5. $file2="file2"
  6. $file3="file3"
  7. $source_location1="source1"
  8. $source_location2="source2"
  9. $source_location3="source3"
  10. $dest1="destination1"
  11. $dest2="destination2"
  12. $dest2="destination3"
  13. $date="datenow"
A small part of script look like this

while ($i<3)
log into server (i)
file $move(i) from $source(i) to $dest(i)
exec(a few DOS commands such as rename, run other batch shop with input $file(i) $dest(i))
Output to log files (echo. "File "$file(i) to $file (i+1)" ".$date)
Perform a few cleanup operations on file(i)
END While

Or is there an easier mechanism for the above sort of script?
Thank you,
Farhad
Look at this thread:
http://www.scriptftp.com/forum/viewtopic.php?f=6&t=508

Basically each part sets up expected variables (your $var(i)), then calls a routine which does the work. So each array "group" would simply set up common variables. There would be no while loop.
FTP Script
  1. # process GH
  2.     $return = 1
  3.     $localDir = "GH"
  4.     $userName = "xxxx"
  5.     $password = "xxxx"
  6.  
  7.     goto :aprocessFiles
  8.  
  9. :Return1
and so on
Thanks for answering Bucket