1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to? RT execution stuck on same file

Discussion in 'Support' started by Robert Kantor, Nov 1, 2016.

  1. Robert Kantor

    Joined:
    Aug 11, 2014
    Messages:
    18
    Likes Received:
    0
    Hello. This script when run from the IDE runs properly and goes through all the files on the ftp server. When I run this via the RT on my server, the same file is restarted once it gets to the end of the file to re-download. I am not sure why this occurs via the RT and works as expected with the Take Command IDE/Debugger?

    The code below uses my desktop folder where the real server uses a folder under the documents folder structure.

    Ideas?

    FTP Process.png
     
  2. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    What is the "find" command in your :checkval?
    If I do a which on it, I get...
    Code:
    [C:\BIN\JPSoft\TCMD20]
    11:25:34 $ which find
    find is an external : C:\cygwin64\bin\find.exe
    Could you mean "ffind"?
     
  3. Robert Kantor

    Joined:
    Aug 11, 2014
    Messages:
    18
    Likes Received:
    0
    Na tive windows find...

    Which Find.png
     
  4. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Heh... I must have my Cygwin before my system dir in my path.
     
  5. Robert Kantor

    Joined:
    Aug 11, 2014
    Messages:
    18
    Likes Received:
    0
    As soon as the file finishes, it restarts. The difference is on my workstations it shows 1 file copied and moves to the next file, on the server it restarts and it does not show the 1 file copied message.

    This test btm creates an infinite copy loop on my server. Downloads and restarts.

    Testcopy_btm.png
     
  6. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    I think you should be using %1 instead of %a in your :checkval and :notfound

    Still tinkering.
     
  7. Robert Kantor

    Joined:
    Aug 11, 2014
    Messages:
    18
    Likes Received:
    0
    I'll check that. I am starting to think the copy from the ftp in the runtime has a bug... Since I can reproduce without any of the logic but the copy command.
     
  8. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    Could you be more specific about "the file" and "it restarts"? Do you mean it keeps processing the same file over and over?
    Here's how I would process the files:
    Code:
    iftp ftp://xxx
    dir /b /a:-d ftp: > foo1.txt
    tpipe /inputfile=process.txt /merge=2,foo1.txt /output=foo.txt
    do f in @foo.txt
      copy ftp:%f ...
    enddo
    copy process.txt + foo.txt process.txt
    iftp /c
    
     
  9. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    I translated it just a bit. And I get exactly the same output from TCC v20, IDE, and TCC-RT. That output appears far below.

    Three comments.

    Do you really want it to process ".." and subdirectories?
    I'd recommend DO instead of FOR.
    I'd recommend GOSUB/RETURN instead of CALL/GOTO :EOF.

    Code:
    @echo off
    for /f %a in ( 'dir ftp://lucky.syr.edu/4plugins/* /1 /F') do (call :checkval "%a")
    goto :eof
    
    :checkval
       find "%a" v:\process.txt
       if %errorlevel% equ 1 goto :notfound
       echo found - skipping
       goto :eof
      
    :notfound
       echo not found - process file
           (echo %a >> v:\process.txt & copy %a v:\)
           goto :eof
    Code:
    File not found - V:\PROCESS.TXT
    not found - process file
    ftp://lucky.syr.edu/4plugins/./4autotray.zip => V:\4autotray.zip
    ftp://lucky.syr.edu/4plugins/./4console.zip => V:\4console.zip
    ftp://lucky.syr.edu/4plugins/./4utils.zip => V:\4utils.zip
    ftp://lucky.syr.edu/4plugins/./ev.zip => V:\ev.zip
    ftp://lucky.syr.edu/4plugins/./sysutils.zip => V:\sysutils.zip
         5 files copied
    
    ---------- V:\PROCESS.TXT
    not found - process file
    ftp://lucky.syr.edu/4plugins/../arnex4.JPG => V:\arnex4.JPG
    ftp://lucky.syr.edu/4plugins/../DynamicSetEnvVar.zip => V:\DynamicSetEnvVar.zip
    ftp://lucky.syr.edu/4plugins/../DynamicSetEnvVar64.zip => V:\DynamicSetEnvVar64.zip
    ftp://lucky.syr.edu/4plugins/../ipv4.zip => V:\ipv4.zip
    ftp://lucky.syr.edu/4plugins/../lucky.crt => V:\lucky.crt
    ftp://lucky.syr.edu/4plugins/../MercOnSvcDesk.png => V:\MercOnSvcDesk.png
    ftp://lucky.syr.edu/4plugins/../pset.zip => V:\pset.zip
    ftp://lucky.syr.edu/4plugins/../Thumbs.db => V:\Thumbs.db
         8 files copied
    
    ---------- V:\PROCESS.TXT
    not found - process file
    ftp://lucky.syr.edu/4plugins/X64/4autotray64.zip => V:\4autotray64.zip
    ftp://lucky.syr.edu/4plugins/X64/4console64.zip => V:\4console64.zip
    ftp://lucky.syr.edu/4plugins/X64/4utils64.zip => V:\4utils64.zip
    ftp://lucky.syr.edu/4plugins/X64/ev64.zip => V:\ev64.zip
    ftp://lucky.syr.edu/4plugins/X64/sysutils64.zip => V:\sysutils64.zip
         5 files copied
    
    ---------- V:\PROCESS.TXT
    not found - process file
    ftp://lucky.syr.edu/4plugins/4autotray.zip => V:\4autotray.zip
         1 file copied
    
    ---------- V:\PROCESS.TXT
    not found - process file
    ftp://lucky.syr.edu/4plugins/4console.zip => V:\4console.zip
         1 file copied
    
    ---------- V:\PROCESS.TXT
    not found - process file
    ftp://lucky.syr.edu/4plugins/4utils.zip => V:\4utils.zip
         1 file copied
    
    ---------- V:\PROCESS.TXT
    not found - process file
    ftp://lucky.syr.edu/4plugins/ev.zip => V:\ev.zip
         1 file copied
    
    ---------- V:\PROCESS.TXT
    not found - process file
    ftp://lucky.syr.edu/4plugins/sysutils.zip => V:\sysutils.zip
         1 file copied
     
  10. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    If you used Cygwin, you could just
    Code:
    lftp -c "open ftp://ftp.theftpsite.com && cd theremotepath && mirror"
    But I'm still checking it out in the BTM file.
     
  11. Robert Kantor

    Joined:
    Aug 11, 2014
    Messages:
    18
    Likes Received:
    0
    Yes, the copy of the file restarts, once it reaches the end, almost like it cannot close the file. If I press Ctrl-C and I answer Y to cancel, it will then move to the next file.

    Strange.
     
  12. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    Whoops. I got that backwards. The TPIPE command should be:
    Code:
    tpipe /inputfile=foo1.txt /merge=2,process.txt /output=foo.txt
    
     
  13. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    Third time's the charm
    Code:
    iftp ftp://lucky.syr.edu/4plugins
    dir /b /a:-d ftp: > foo1.txt
    tpipe /input=foo1.txt /merge=2,process.txt /output=foo.txt
    do f in @foo.txt
      copy ftp:%f .
    enddo
    type foo.txt >> process.txt
    iftp /c
    
     
  14. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    Here's a rewrite using (more or less) the original strategy.
    Code:
    do a in ftp://lucky.syr.edu/4plugins/*
       iff %@exec[find "%a" v:\process.txt > NUL] == 1 then
           echo not found - process file
           echo %a >> v:\process.txt
           copy "%a" v:\
       else
           echo found - skipping
       endiff
    enddo
     
  15. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    I did find while testing that there were a lot of extra double quotes floating around, but now, this works for me and it's basically what you started with...
    Code:
    for /f %a in ('dir ftp://ftpsite/* /1 /F') do (call :checkval %a)
    goto :eof
    
    :checkval
        \windows\system32\find "%1" c:\temp\process.txt
        if %errorlevel equ 1 goto :notfound
        echo found %1 - skipping
        goto :eof
    
    :notfound
        echo notfound - process file
        (echo %1 >> c:\temp\process.txt & copy %1 .)
        goto :eof
    
    Edit: As a side note, I discovered we have several very large files parked on our FTP server. :)
    Edit: As an afterthought, the extra double quotes may have come from switching from the %a to the %1
     
  16. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    Get rid of FIND.EXE (and avoid TPIPE) like this.
    Code:
    do a in ftp://lucky.syr.edu/4plugins/*
       iff "%@execstr[ffind /k /m /t"%a" v:\process.txt]" == "" then
           echo not found - process file
           echo %a >> v:\process.txt
           copy "%a" v:\
       else
           echo found - skipping
       endiff
    enddo
    
     
  17. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,860
    Likes Received:
    83
    This is usually due to the way Windows and the FOR command operates - it iterates through the directory, and if files are updated / added / moved then FOR can return the same file more than once. It's safer to use a file list (@file).
     

Share This Page