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?
Is there a script to check for zero bytes or empty file so we do not replace the existing file on the FTP site?
Hi,

You can check the size of a file with the command GETFILESIZE. It works this way:


FTP Script
  1. $file_size=GETFILESIZE(LOCAL,"data.log")
  2.  
  3. # Upload the file data.log only if its size is greater than 0
  4. IF($file_size>0)
  5.     PUTFILE("data.log")


You can find more info and some examples here:
https://www.scriptftp.com/d/ftp-file-commands/getfilesize

Also, if you are uploading many files you will have to use it within a FOREACH loop:
https://www.scriptftp.com/d/ftp-script-for-windows-getting-started/lesson-5-foreach-handling-file-lists
Why do you have to use the FOREACH loop when uploading many files? What kind of issues do you get if you don't? I'm just curious.
You can avoid using FOREACH if you want. For example:


FTP Script
  1. PUTFILE("*.*",SUBDIRS)


But sometimes it is preferred to use FOREACH to do some operations per file. For example:


FTP Script
  1. # Only upload files in the list which file size is greater than 100 bytes
  2. FOREACH $file IN $list
  3.     $file_size=GETFILESIZE(LOCAL,"data.log")
  4.     IF($file_size>100)
  5.          PUTFILE($file)
  6.     END IF