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.
Post here if you experience file transfer problems or unexpected errors.
Hi,
I want to incorporate a check in my script.
If local/remote directory is {empty}
then
Wait...
Else
upload files

I know that we can use the getlist command
FTP Script
  1. GETLIST($mylist,LOCAL_FILES,"*.*")
but then??
how can i check the $mylist if it is empty?
Will it work with something like this
FTP Script
  1. GETLIST($mylist,LOCAL_FILES,"*.*")
  2. $result=PUTFILE($txtfile)
  3.     IF($result=="OK")
  4.         upload files
  5.     ELSE
  6.       PRINT("Directory is empty.")
  7.     END IF
  8.   
Thanks
Using the COUNTELEMENTS command. Very easy:
FTP Script
  1. # This is a label it marks a point in the script. It is used to jump here.
  2. :start
  3.  
  4. # Get the local file listing, store it in $mylist
  5. GETLIST($mylist,LOCAL_FILES)
  6.  
  7. # Calculate the number of elements in the list
  8. $number_of_elements=COUNTELEMENTS($list)
  9.  
  10. IF($mylist==0)
  11.   PRINT("No files found. Waiting 5 seconds.")
  12.   SLEEP(5)
  13.   PRINT("Trying agin")
  14.   GOTO :start  
  15.  
  16.  
  17. PRINT("Found ".$number_of_elements." files")
  18.  
  19. # Upload the files
  20. OPENHOST("ftp.myhost.com","myuser","mypass")
  21.  
  22. FOREACH $file IN $mylist
  23.     PUTFILE($file)
  24.  
  25.  
WOO

this is great :)
When i have finalized my script i will send it to you :)
Think it's a nice example and good usable for some people :)

I don't know much about programming but ScriptFTP i do understand...with some help of you haha
Know i need to know how to upload a whol directory at once, similiar to dos command "mput"

thanks
Hi Admin.

I implemented your coding but for some reason it's not processing if the results is larger then fe 1.
It see's that there are 2 files but then it goes back to : startdir and again checks and sees it has 2 files.
it will not go to :checkconnection.

I tried also the other way around. but then it keeps processing and does no wait..
Any idea? I tried also a WHILE but that didn't help either.

Thanks
FTP Script
  1. ########################################################################################
  2. # Check if the directory is empty, or if it contains files to process
  3. ########################################################################################
  4. :startdir
  5. LOCALCHDIR($local_dir)
  6. GETLIST($checklist,LOCAL_FILES)
  7. $number_of_elements=COUNTELEMENTS($list)
  8. IF ($checklist<=1)
  9.   SLEEP(10)
  10.   GOTO :startdir
  11.   ELSE
  12.   GOTO :checkconnection
  13. ########################################################################################
  14. # Check if Connection is live
  15. ########################################################################################
  16. :checkconnection
  17. LOGTO($logfile,APPEND)
  18.    PRINT("Connection is still valid")
  19.    GOTO :batch1
  20.    PRINT("Connection is broken. Reconnecting.")
  21.    GOTO :reconnect
  22.    END IF
  23. ########################################################################################
  24. # Create trigger files for each original file and move the files to a TEMP folder
  25. ########################################################################################
  26. :batch1
  27. LOCALCHDIR($local_dir)
  28. GETLIST($mylist,LOCAL_FILES,"*.txt")
  29. FOREACH $txtfile IN $mylist
  30.     EXEC("move ".$txtfile." D:\abg\SOIRedPrairie\export\temp\".$txtfile)
  31.     $windows_filename=TEXTCUT($txtfile,1,TEXTLENGTH($txtfile)-4)
  32.     $trgfilename=$windows_filename.".trg"
  33.     EXEC("D:\FTP_Upload\scripts\touch.exe D:\abg\SOIRedPrairie\export\temp\".$trgfilename)
  34. #########################################################################
Hello,

If I have understood correctly you wish to check if the directory is empty:
IF ($checklist<=1)
For me you are checking for 1 or less, :?

HTH.

Zythan
HI Zythan,

Indeed I want to check if directory is empty but during my tests i even tried to look for <=1
Nothing works..
Try yourself the script i placed here, you will see that it never
FTP Script
  1. :startdir
  2. LOCALCHDIR($local_dir)
  3. GETLIST($mylist,LOCAL_FILES)
  4. $number_of_elements=COUNTELEMENTS($list)
  5.  
  6.  
  7. IF($mylist>=1)
  8.   GOTO :files
  9.   PRINT("No files found. Waiting 5 seconds.")
  10.   SLEEP(5)
  11.   PRINT("Trying again")
  12.   GOTO :startdir  
  13.  
  14. :files
  15. PRINT("Found some files")
  16. goto :startdir
I think it's somewhere in the if $mylist>=1 or in the counting of the elements.
Thanks
Okay, I found the error :)

With the code below it realy checks and executes the correct path....
FTP Script
  1. # Get the local file listing, store it in $mylist
  2. GETLIST($mylist,LOCAL_FILES)
  3.  
  4. # Calculate the number of elements in the list
  5. $number_of_elements=COUNTELEMENTS($mylist)
  6.  
  7. IF($number_of_elements==0)
  8.   PRINT("No files found. Waiting 5 seconds.")
  9.   SLEEP(5)
  10.   PRINT("Trying again")
  11.   GOTO :start  
  12.  
  13. PRINT("Found ".$number_of_elements." files")
  14.  
  15. # Upload the files
  16. OPENHOST("ftp.myhost.com","myuser","mypass")
  17.  
  18. FOREACH $file IN $mylist
  19.     PUTFILE($file)
  20.  
  21.