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 all,

I encountered a problem yesterday trying to download a file and it turns out he was empty. But in fact he's not.
I am thinking that scriptftp was starting to downloading before the file has been moved completely in ftp folder.
At this moment our code is:

[scriptftp="ftp_transfer.ftp"]# Connect to the FTP server
$result=OPENHOST($ftp_server,$ftp_user,$ftp_password)
IF($result!="OK")
PRINT("Cannot connect to FTP server. Sending an email and aborting in 5 seconds.")
EXEC($blat_cmd_line_1)
SLEEP(5)
EXIT(1)
END IF


#Définition du répertoire local
LOCALCHDIR("D:\EDI\PTD\GVH\PROD\IN\GATEIN")

#Définition du répertoire distant
CHDIR("/autotrans/GateIn")


# Get the local file listing, store it in $list
GETLIST($list,REMOTE_FILES,"BORGATEIN*.TXT")


# For each file in $list...
FOREACH $item IN $list
# Download the file
$result=GETFILE($item)

# If the file has been downloaded successfully
# delete the remote copy. Else stop the script.
IF($result=="OK")
DELETEFILE($item)
ELSE
STOP
EXIT(2)
END IF
END FOREACH


CLOSEHOST

EXIT(0)[/ScriptFTP]

We are trying to download files with a trailer at the end of each message.

Can I check if the trailer is present (inside the message) and if so download the file, otherwise wait for 10 seconds ?
downloading before the file has been moved completely in ftp folder.
Most FTP servers report that a file has 0 bytes in size if the file is being moved or copied in that precise moment. I suggest you to try this:

[scriptftp="check_file_before_download.ftp"]# For each file in $list...
FOREACH $item IN $list

# check if the file is being written
IF(GETFILESIZE(REMOTE, $item))
# Wait for 10 seconds
SLEEP(10)
END IF

# Download the file
$result=GETFILE($item)

# If the file has been downloaded successfully
# delete the remote copy. Else stop the script.
IF($result=="OK")
DELETEFILE($item)
ELSE
STOP
EXIT(2)
END IF
END FOREACH[/ScriptFTP]