Only download if other file does not exist

Post here if you experience file transfer problems or unexpected errors.

Only download if other file does not exist

Postby efiten » 29 Feb 2012, 15:18

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 iconFTP Script: [ Download ] [ Hide ]
GETLIST($list, LOCAL_FILES, "*.*")
 
CLEAREXCLUSION()
 
FOREACH $item IN $list
   ADDEXCLUSION(DOWNLOAD, $item)
 END FOREACH

But I don't know if i can exlude the name with ALL the extensions ?
someting like :
Code: Select all
ADDEXCLUSION(DOWNLOAD, $item.*)
efiten
 
Posts: 7
Joined: 21 Nov 2011, 08:57

Re: Only download if other file does not exist

Postby WAndrey » 29 Feb 2012, 20:44

efiten wrote: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.
WAndrey
 
Posts: 76
Joined: 24 Dec 2009, 14:28

Re: Only download if other file does not exist

Postby WAndrey » 29 Feb 2012, 20:48

efiten wrote:But I don't know if i can exlude the name with ALL the extensions ?
someting like :
Code: Select all
ADDEXCLUSION(DOWNLOAD, $item.*)
how to retrieve the suffix from the name of a file
WAndrey
 
Posts: 76
Joined: 24 Dec 2009, 14:28

Re: Only download if other file does not exist

Postby WAndrey » 29 Feb 2012, 21:15

Maybe so? Efficiency is not checked. Sorry for my English, I used translate.google.com
ftp script iconFTP Script: [ Download ] [ Hide ]
GETLIST($aLocalList, LOCAL_FILES, "*.MPG")
GETLIST($aRemoteList, REMOTE_FILES, "*.PS")

$aLocalName = ""
$aRemoteName = ""
 
FOREACH $aFileName IN $aLocalList
  $i = TEXTLENGTH($aFileName)
#  $aName = $aFileName
#  $aExt = ""
  WHILE($i > 0)
    IF(TEXTCUT($aFileName, $i, 1) == ".")
      $aName = TEXTCUT($aFileName, 1, $i-1)
#      $aExt = TEXTCUT($aFileName, $i+1, TEXTLENGTH($aFileName)-$i)
      $i = 0
    END IF
    $i = $i-1
  END WHILE
  $aLocalName = $aLocalName.$aName."|"
END FOREACH

FOREACH $aFileName IN $aRemotelist
  $i = TEXTLENGTH($aFileName)
#  $aName = $aFileName
#  $aExt = ""
  WHILE($i > 0)
    IF(TEXTCUT($aFileName, $i, 1) == ".")
      $aName = TEXTCUT($aFileName, 1, $i-1)
#      $aExt = TEXTCUT($aFileName, $i+1, TEXTLENGTH($aFileName)-$i)
      $i = 0
    END IF
    $i = $i-1
  END WHILE
  $aRemoteName = $aRemoteName.$aName."|"
END FOREACH

FOREACH $aRemote IN $aRemoteName
  $aFound = 0
  FOREACH $aLocal IN $aLocalName
    IF($aRemote == $aLocal)
      $aFound = 1
    END IF
  END FOREACH
  IF($aFound == 0)
    GETFILE2($aRemote.".PS", $aRemote.".MPG")
  END IF
END FOREACH
WAndrey
 
Posts: 76
Joined: 24 Dec 2009, 14:28

Re: Only download if other file does not exist

Postby efiten » 01 Mar 2012, 09:20

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.
efiten
 
Posts: 7
Joined: 21 Nov 2011, 08:57

Re: Only download if other file does not exist

Postby efiten » 02 Mar 2012, 08:23

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 iconFTP Script: [ Download ] [ Hide ]
$aLocalName = ""
$aRemoteName = ""

GETLIST($aLocalList, LOCAL_FILES, "*.mpg")

FOREACH $aFileName IN $aLocalList
  $i = TEXTLENGTH($aFileName)
#  $aName = $aFileName
#  $aExt = ""
  WHILE($i > 0)
    IF(TEXTCUT($aFileName, $i, 1) == ".")
      $aName = TEXTCUT($aFileName, 1, $i-1)
#      $aExt = TEXTCUT($aFileName, $i+1, TEXTLENGTH($aFileName)-$i)
      $i = 0
    END IF
    $i = $i-1
  END WHILE
  $aLocalName = $aLocalName.$aName."|"
END FOREACH

FOREACH $aLocal IN $aLocalName
PRINT("Local : ".$aLocal)
END FOREACH

GETLIST($aRemoteList, REMOTE_FILES, "*.ps")

FOREACH $aFileName IN $aRemotelist
  $i = TEXTLENGTH($aFileName)
#  $aName = $aFileName
#  $aExt = ""
  WHILE($i > 0)
    IF(TEXTCUT($aFileName, $i, 1) == ".")
      $aName = TEXTCUT($aFileName, 1, $i-1)
#      $aExt = TEXTCUT($aFileName, $i+1, TEXTLENGTH($aFileName)-$i)
      $i = 0
    END IF
    $i = $i-1
  END WHILE
  $aRemoteName = $aRemoteName.$aName."|"
END FOREACH

FOREACH $aRemote IN $aRemoteName
PRINT("Remote : ".$aRemote)
END FOREACH

FOREACH $aRemote IN $aRemoteName
  $aFound = 0
  FOREACH $aLocal IN $aLocalName
   IF($aRemote == $aLocal)
      $aFound = 1
    END IF
  END FOREACH
  IF($aFound == 0)
    GETFILE2($aRemote.".ps", $aRemote.".mpg")
  END IF
END FOREACH
 


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

efiten
 
Posts: 7
Joined: 21 Nov 2011, 08:57

Re: Only download if other file does not exist

Postby efiten » 02 Mar 2012, 09:28

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 :

ftp script iconFTP Script: [ Download ] [ Hide ]
$aLocalName = "|"
$aRemoteName = "|"


And it works, why ? i don't konw...
efiten
 
Posts: 7
Joined: 21 Nov 2011, 08:57

Re: Only download if other file does not exist

Postby WAndrey » 02 Mar 2012, 12:52

I am guided by the section 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 iconFTP Script: [ Download ] [ Hide ]
GETLIST($aLocalList, LOCAL_FILES, "*.*")
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 iconFTP Script: [ Download ] [ Hide ]
GETLIST($aLocalList, LOCAL_FILES, "*.MPG")
GETLIST($aRemoteList, REMOTE_FILES, "*.PS")

$aLocalName = ""
$aRemoteName = ""
 
FOREACH $aFileName IN $aLocalList
  $i = TEXTLENGTH($aFileName)
#  $aName = $aFileName
#  $aExt = ""
  WHILE($i > 0)
    IF(TEXTCUT($aFileName, $i, 1) == ".")
      $aName = TEXTCUT($aFileName, 1, $i-1)
#      $aExt = TEXTCUT($aFileName, $i+1, TEXTLENGTH($aFileName)-$i)
      $i = 0
    END IF
    $i = $i-1
  END WHILE
  $aLocalName = $aLocalName."|".$aName
END FOREACH

FOREACH $aFileName IN $aRemotelist
  $i = TEXTLENGTH($aFileName)
#  $aName = $aFileName
#  $aExt = ""
  WHILE($i > 0)
    IF(TEXTCUT($aFileName, $i, 1) == ".")
      $aName = TEXTCUT($aFileName, 1, $i-1)
#      $aExt = TEXTCUT($aFileName, $i+1, TEXTLENGTH($aFileName)-$i)
      $i = 0
    END IF
    $i = $i-1
  END WHILE
  $aRemoteName = $aRemoteName."|".$aName
END FOREACH

FOREACH $aRemote IN $aRemoteName
  $aFound = 0
  FOREACH $aLocal IN $aLocalName
    IF($aRemote == $aLocal)
      $aFound = 1
    END IF
  END FOREACH
  IF($aFound == 0)
    GETFILE2($aRemote.".PS", $aRemote.".MPG")
  END IF
END FOREACH
The changes were lines forming the list, the symbol "|" to add an element, but not after.
Sorry for my English, I used translate.google.com
WAndrey
 
Posts: 76
Joined: 24 Dec 2009, 14:28


Return to Troubleshooting



Who is online

Users browsing this forum: No registered users and 1 guest

cron