How to? RT execution stuck on same file

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Aug 11, 2014
18
0
#1
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
 
Jan 19, 2011
559
7
Norman, OK
#2
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"?
 
Jan 19, 2011
559
7
Norman, OK
#4
Heh... I must have my Cygwin before my system dir in my path.
 
Aug 11, 2014
18
0
#5
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
 
Jan 19, 2011
559
7
Norman, OK
#6
I think you should be using %1 instead of %a in your :checkval and :notfound

Still tinkering.
 

samintz

Scott Mintz
May 20, 2008
1,203
11
Solon, OH, USA
#8
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
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
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.
 
Aug 11, 2014
18
0
#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
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.
 

samintz

Scott Mintz
May 20, 2008
1,203
11
Solon, OH, USA
#13
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
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
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
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
 

rconn

Administrator
Staff member
May 14, 2008
10,100
85
#17
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?
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).