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.
I use ScriptFTP to download files with the extension *.PS
When downloaded, they are renamed to *.MPG (can this be easy done inside the script, now I do it after the FTP with a batch file in the task-scheduler)

The FTP session is also started with the task-scheduler, every 15 minutes, so if there 's a new file in the FTP side, it will be downloaded, but, since i rename the files to *.MPG the file is downloaded again and again.

So is there a way i can check it ?

if FILE1.MPG exists local , do NOT download FILE1.PS
if FILE1.MPG does NOT exist local, download file1.PS and rename it after download to FILE1.MPG

this has to be done for all the files on the remote FTP.

I was thinking of using the script :
FTP Script
  1. GETLIST($list, LOCAL_FILES, "*.*")
  2.  
  3.  
  4. FOREACH $item IN $list
  5.    ADDEXCLUSION(DOWNLOAD, $item)
But I don't know if i can exlude the name with ALL the extensions ?
someting like :
FTP Script
  1. ADDEXCLUSION(DOWNLOAD, $item.*)
I use ScriptFTP to download files with the extension *.PS
When downloaded, they are renamed to *.MPG (can this be easy done inside the script, now I do it after the FTP with a batch file in the task-scheduler)
Download the specified file and save it using a different name.
But I don't know if i can exlude the name with ALL the extensions ?
someting like :
ADDEXCLUSION(DOWNLOAD, $item.*)
http://www.scriptftp.com/forum/viewtopic.php?f=6&t=614
(how to retrieve the suffix from the name of a file)
Maybe so? Efficiency is not checked. Sorry for my English, I used Google Translate
FTP Script
  1. GETLIST($aLocalList, LOCAL_FILES, "*.MPG")
  2. GETLIST($aRemoteList, REMOTE_FILES, "*.PS")
  3.  
  4. $aLocalName = ""
  5. $aRemoteName = ""
  6.  
  7. FOREACH $aFileName IN $aLocalList
  8.   $i = TEXTLENGTH($aFileName)
  9. #  $aName = $aFileName
  10. #  $aExt = ""
  11.   WHILE($i > 0)
  12.     IF(TEXTCUT($aFileName, $i, 1) == ".")
  13.       $aName = TEXTCUT($aFileName, 1, $i-1)
  14. #      $aExt = TEXTCUT($aFileName, $i+1, TEXTLENGTH($aFileName)-$i)
  15.       $i = 0
  16.     END IF
  17.     $i = $i-1
  18.   $aLocalName = $aLocalName.$aName."|"
  19.  
  20. FOREACH $aFileName IN $aRemotelist
  21.   $i = TEXTLENGTH($aFileName)
  22. #  $aName = $aFileName
  23. #  $aExt = ""
  24.   WHILE($i > 0)
  25.     IF(TEXTCUT($aFileName, $i, 1) == ".")
  26.       $aName = TEXTCUT($aFileName, 1, $i-1)
  27. #      $aExt = TEXTCUT($aFileName, $i+1, TEXTLENGTH($aFileName)-$i)
  28.       $i = 0
  29.     END IF
  30.     $i = $i-1
  31.   $aRemoteName = $aRemoteName.$aName."|"
  32.  
  33. FOREACH $aRemote IN $aRemoteName
  34.   $aFound = 0
  35.   FOREACH $aLocal IN $aLocalName
  36.     IF($aRemote == $aLocal)
  37.       $aFound = 1
  38.     END IF
  39.   IF($aFound == 0)
  40.     GETFILE2($aRemote.".PS", $aRemote.".MPG")
  41.   END IF
I'm testing it at the moment, it looks good, the only thing I had to change was putting the extension in lower case, as the FTP is linux based.

Many thanks for this great help.
I'll let you know when the testing is finished, and if I had to make some changes.
It's not completely OK.
It is strange, but it seems to miss the first LOCAL file in the list.
the REMOTE list is OK
I added a print commando; to view the filenames :
FTP Script
  1. $aLocalName = ""
  2. $aRemoteName = ""
  3.  
  4. GETLIST($aLocalList, LOCAL_FILES, "*.mpg")
  5.  
  6. FOREACH $aFileName IN $aLocalList
  7.   $i = TEXTLENGTH($aFileName)
  8. #  $aName = $aFileName
  9. #  $aExt = ""
  10.   WHILE($i > 0)
  11.     IF(TEXTCUT($aFileName, $i, 1) == ".")
  12.       $aName = TEXTCUT($aFileName, 1, $i-1)
  13. #      $aExt = TEXTCUT($aFileName, $i+1, TEXTLENGTH($aFileName)-$i)
  14.       $i = 0
  15.     END IF
  16.     $i = $i-1
  17.   $aLocalName = $aLocalName.$aName."|"
  18.  
  19. FOREACH $aLocal IN $aLocalName
  20. PRINT("Local : ".$aLocal)
  21.  
  22. GETLIST($aRemoteList, REMOTE_FILES, "*.ps")
  23.  
  24. FOREACH $aFileName IN $aRemotelist
  25.   $i = TEXTLENGTH($aFileName)
  26. #  $aName = $aFileName
  27. #  $aExt = ""
  28.   WHILE($i > 0)
  29.     IF(TEXTCUT($aFileName, $i, 1) == ".")
  30.       $aName = TEXTCUT($aFileName, 1, $i-1)
  31. #      $aExt = TEXTCUT($aFileName, $i+1, TEXTLENGTH($aFileName)-$i)
  32.       $i = 0
  33.     END IF
  34.     $i = $i-1
  35.   $aRemoteName = $aRemoteName.$aName."|"
  36.  
  37. FOREACH $aRemote IN $aRemoteName
  38. PRINT("Remote : ".$aRemote)
  39.  
  40. FOREACH $aRemote IN $aRemoteName
  41.   $aFound = 0
  42.   FOREACH $aLocal IN $aLocalName
  43.    IF($aRemote == $aLocal)
  44.       $aFound = 1
  45.     END IF
  46.   IF($aFound == 0)
  47.     GETFILE2($aRemote.".ps", $aRemote.".mpg")
  48.   END IF
And after a few files it goes wrong, the local and remote files do not match, and they do exist.
GETLIST(LOCAL_FILES,"*.mpg")
Getting file listing of current local directory
Found 9 files.
Local : JPL_PGM_W26_MON-GNK_N
Local : JPL_PGM_W26_OHL-CER_N
Local : JPL_PGM_W26_STV-LIE_N
Local : JPL_PGM_W27_BEE-OHL_N
Local : JPL_PGM_W27_CER-ZWA_N
Local : JPL_PGM_W27_GNT-MON_N
Local : JPL_PGM_W27_KOR-LOK_N
Local : JPL_PGM_W27_WES-MEC_N
Local :

GETLIST(REMOTE_FILES,"*.ps")
Getting file listing of current remote directory
Found 10 files.
Remote : JPL_PGM_W26_MEC-BEE_N
Remote : JPL_PGM_W26_MON-GNK_N
Remote : JPL_PGM_W26_OHL-CER_N
Remote : JPL_PGM_W26_STV-LIE_N
Remote : JPL_PGM_W27_BEE-OHL_N
Remote : JPL_PGM_W27_CER-ZWA_N
Remote : JPL_PGM_W27_GNT-MON_N
Remote : JPL_PGM_W27_KOR-LOK_N
Remote : JPL_PGM_W27_WES-MEC_N
Remote :


GETFILE2("JPL_PGM_W26_MEC-BEE_N.ps","JPL_PGM_W26_MEC-BEE_N.mpg")
Downloading................. JPL_PGM_W26_MEC-BEE_N.ps as JPL_PGM_W26_MEC-BEE_N.mpg
Update :

With the PRINT commando I tried to debug it.
strange enough, when I set the $aLocalName and $aRemoteNamet to "|" the script works, so I did :

[ScriptFTP]$aLocalName = "|"
$aRemoteName = "|"[/ScriptFTP]

And it works, why ? i don't konw...
I am guided by the section

https://www.scriptftp.com/d/ftp-miscellaneous-commands/getlist

where it is stated:
Every ScriptFTP variable contains a text string and the list that this command creates is not an exception. The character "|" is used to separate the items of the list. Therefore, you can also build file lists without GETLIST. For example: $mylist="a.txt|b.txt|c.txt".
A checking this code:
FTP Script
  1. GETLIST($aLocalList, LOCAL_FILES, "*.*")
  2. PRINT($aLocalList)
I got
|1.ftp|AUTOEXEC.BAT|boot.ini|Bootfont.bin|CONFIG.SYS|IO.SYS|Log.txt|MSDOS.SYS|NTDETECT.COM|ntldr|pagefile.sys
Thus we see an inaccuracy in the documentation and the code should look like this:
FTP Script
  1. GETLIST($aLocalList, LOCAL_FILES, "*.MPG")
  2. GETLIST($aRemoteList, REMOTE_FILES, "*.PS")
  3.  
  4. $aLocalName = ""
  5. $aRemoteName = ""
  6.  
  7. FOREACH $aFileName IN $aLocalList
  8.   $i = TEXTLENGTH($aFileName)
  9. #  $aName = $aFileName
  10. #  $aExt = ""
  11.   WHILE($i > 0)
  12.     IF(TEXTCUT($aFileName, $i, 1) == ".")
  13.       $aName = TEXTCUT($aFileName, 1, $i-1)
  14. #      $aExt = TEXTCUT($aFileName, $i+1, TEXTLENGTH($aFileName)-$i)
  15.       $i = 0
  16.     END IF
  17.     $i = $i-1
  18.   $aLocalName = $aLocalName."|".$aName
  19.  
  20. FOREACH $aFileName IN $aRemotelist
  21.   $i = TEXTLENGTH($aFileName)
  22. #  $aName = $aFileName
  23. #  $aExt = ""
  24.   WHILE($i > 0)
  25.     IF(TEXTCUT($aFileName, $i, 1) == ".")
  26.       $aName = TEXTCUT($aFileName, 1, $i-1)
  27. #      $aExt = TEXTCUT($aFileName, $i+1, TEXTLENGTH($aFileName)-$i)
  28.       $i = 0
  29.     END IF
  30.     $i = $i-1
  31.   $aRemoteName = $aRemoteName."|".$aName
  32.  
  33. FOREACH $aRemote IN $aRemoteName
  34.   $aFound = 0
  35.   FOREACH $aLocal IN $aLocalName
  36.     IF($aRemote == $aLocal)
  37.       $aFound = 1
  38.     END IF
  39.   IF($aFound == 0)
  40.     GETFILE2($aRemote.".PS", $aRemote.".MPG")
  41.   END IF
The changes were lines forming the list, the symbol "|" to add an element, but not after.
Sorry for my English, I used google translator