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?
Hello,
First :
i try to make a script to list directories and subdirectories on my server.
The script below works but is it possible to do it in a better way?
FTP Script
  1. $host="myftp"
  2. $user="myusername"
  3. $password="mypassword"
  4. SETPORT(2121)
  5.  
  6. :start
  7. # Connect to FTP server
  8. $result=openhost($host,$user,$password)
  9.  
  10. # check what happened with openhost
  11. IF($result=="OK")
  12.     PRINT("CONNECTED")
  13.     PRINT("Cannot connect. Waiting 5 seconds.")
  14.     SLEEP(5)
  15.     GOTO :start
  16.  
  17. $listfinal=""
  18.  
  19. GETLIST($list0,REMOTE_DIRECTORIES)
  20.  
  21. # For each directory in $list print the name
  22. FOREACH $item0 IN $list0
  23.     $newdir0="/".$item0
  24.     Print("0 ".$newdir0)
  25.     chdir($newdir0)
  26.     if ($listfinal=="")
  27.         $listfinal=$newdir0
  28.     else
  29.         $listfinal=$listfinal."|".$newdir0
  30.     end if
  31.     GETLIST($list1,REMOTE_DIRECTORIES)
  32.     FOREACH $item1 IN $list1
  33.         $newdir1=$newdir0."/".$item1
  34.         chdir($newdir1)
  35.         Print("1 ".$newdir1)
  36.         $listfinal=$listfinal."|".$newdir1
  37.         GETLIST($list2,REMOTE_DIRECTORIES)
  38.         FOREACH $item2 IN $list2
  39.             $newdir2=$newdir1."/".$item2
  40.             chdir($newdir2)
  41.             Print("2 ".$newdir2)
  42.             $listfinal=$listfinal."|".$newdir2
  43.             GETLIST($list3,REMOTE_DIRECTORIES)
  44.             FOREACH $item3 IN $list3
  45.                 $newdir3=$newdir2."/".$item3
  46.                 PRINT("3 ".$newdir3)
  47.                 chdir($newdir3)
  48.                 $listfinal=$listfinal."|".$newdir3
  49.                 GETLIST($list4,REMOTE_DIRECTORIES)
  50.                 FOREACH $item4 IN $list4
  51.                     $newdir4=$newdir3."/".$item4
  52.                     Print("4 ".$newdir4)
  53.                     chdir($newdir4)
  54.                     $listfinal=$listfinal."|".$newdir4
  55.                     GETLIST($list5,REMOTE_DIRECTORIES)
  56.                     FOREACH $item5 IN $list5
  57.                         $newdir5=$newdir4."/".$item5
  58.                         Print("5 ".$newdir5)
  59.                         $listfinal=$listfinal."|".$newdir5
  60.                         chdir($newdir5)
  61.                         GETLIST($list6,REMOTE_DIRECTORIES)
  62.                         FOREACH $item6 IN $list6
  63.                             $newdir6=$newdir5."/".$item6
  64.                             Print("6 ".$newdir6)
  65.                             $listfinal=$listfinal."|".$newdir6
  66.                         END FOREACH
  67.                     END FOREACH
  68.                 END FOREACH
  69.             END FOREACH
  70.         END FOREACH
  71.     END FOREACH
  72.  
  73. PRINT("FINISHED")
  74. PRINT("##############################################")
  75. $nb_elt=0
  76. LOGTO("C:\TransferLog.txt")
  77. foreach $elt in $listfinal
  78.     PRINT($elt)
  79.     $nb_elt = $nb_elt + 1
  80.  
  81. PRINT("")
  82. PRINT("##############################################")
  83. PRINT("Found ".$nb_elt." filessssssssssss")
  84. PRINT("##############################################")
  85.  
As you see, it's a bit complicate.

second:
is it possible to do the same to retrieve the list of files name and files size ?

Thanks
Hi,

ScriptFTP does not support recursion or function calls (mostly for simplicity) but it is something we plan to do in next releases.

So, at this moment it is not possible to do any of those points. As you noticed, the only way at this moment is to have some nested FOREACH loops, one for each level of folders
Hi,
thanks for your answer.
waiting for next release...
ScriptFTP does not support recursion or function calls
But it can run a script with parameters ;)
Oh yes, that is a nice trick ;) ;) ;)