How to? Instruct COPY to delete file if only partially copied (via FTP)

Feb 23, 2012
240
3
I'm using TCC's copy command to download files via FTP. Occasionally there is an FTP error that aborts the transfer in the middle. In these cases, I find that the partially-copied file remains, giving the appearance that the file was copied correctly, even though it is only a partial file. Instead, I'd like to have COPY automatically delete any partially-copied file upon encountering an FTP error that aborts the transmission. Is there any way to do so?
It occurs to me that I can probably check the %_copy_errors variable and then delete the file if an error occurred; however, I'd much rather be able to just issue the copy command directly with an appropriate flag, if possible.
 
Feb 23, 2012
240
3
Doesn't the /J option allow COPY to restart? It would make deleting the partial target file wasteful!

OK, let's say I use /J as I download a batch of 100 files. Is there then any way to query the 100 resulting files to determine which are complete and which have only been partially downloaded?
 
May 20, 2008
3,515
4
Elkridge, MD, USA
The last one created on the target is the only one which may be potentially incomplete, assuming a single COPY command was used for all 100 files. I presume your download problems refer to premature termination (which results in not more than one file being incomplete, and others may never have been started), not to a communication link which results in many transfer errors (which I would hope the File Transfer Protocol would have detected and corrected).
 
Feb 23, 2012
240
3
The last one created on the target is the only one which may be potentially incomplete, assuming a single COPY command was used for all 100 files. I presume your download problems refer to premature termination (which results in not more than one file being incomplete, and others may never have been started), not to a communication link which results in many transfer errors (which I would hope the File Transfer Protocol would have detected and corrected).

Actually, I'm running a batch file that runs an individual COPY command for each file. What I'm finding now is that if a copy somewhere in the middle of the batch file terminates prematurely (due to the ftp connection timing out), an incomplete file stays in the directory, and the batch file then continues with the next copy command.
 

rconn

Administrator
Staff member
May 14, 2008
12,356
150
COPY will return a non-zero error if the file isn't fully copied (and if you're paranoid, you can add /V). COPY will not automatically delete the file on an error (though the only time you'll get a partial file is on an FTP copy, because that isn't supported by the Windows CopyFile API).
 
May 20, 2008
3,515
4
Elkridge, MD, USA
Charles:
Yes - watch when you download protected files. I've done that ever since it became available.

Avi:
Your batch file should check each instance of COPY to verify it was successful, and reissue it if not. You have both the exit code from COPY and the %_copy_errors internal variable to provide that information. This could be the style:

do file in @list
copy /j ftp:%file ...
do while %_copy_errors gt 0
copy /j ftp:%file ...
enddo
enddo
--
HTH, Steve
 
Similar threads
Thread starter Title Forum Replies Date
C Copy (sys) error Support 3
Alpengreis Fixed Crash after copy dialog with big TCC.exception.log Support 5
vefatica Copy/Paste anomaly Support 4
D Documentation Typo in COPY help Support 0
samintz COPY fails to copy from \\wsl$ Support 20
D Differences between TCC and CMD with COPY /b Support 4
fpefpe copy /u and timestamps Support 4
M Strange error messages from TCC in FTP copy Support 7
G TCMD crash when copy Support 3
Alpengreis How to? Copy DIRs with attributes ... Support 4
E Text copy bug Support 1
Alpengreis [TCMD v25.00.24] Problem with copy and paste and the # char via mouse in TCC Support 6
fpefpe copy/cat Support 7
K copy /w slow relative to robocopy /mir Support 0
Jay Sage Problem with Context Menu Copy+Paste+Run Key Assignment Support 7
K "copy /z /w" command not deleting read-only files in destination Support 10
K copy changing destination current directory Support 1
D Keystroke to copy previous argument Support 3
A How to? Copy+Paste in TCMD tabs with Ctrl-Shift-Ins? Support 5
RChrismon How to? Copy TCMD.INI to New Version Support 7
R How to? Append files in multiple subfolders using copy? Support 8
Dick Johnson COPY /u (?) Support 9
fpefpe Documentation copy /u Support 7
R How to? copy /q ABC.txt + DEF.txt is appending hex 1A Support 8
D copy /g only shows transfer rate Support 1
J Error "Contents lost before copy" Support 3
B Can copy command concatenate multiple mp3 files Support 2
rps Documentation "Copy+Paste+run" question Support 2
kb6ojs Make /G parameter persistent in COPY/MOVE command? Support 4
fpefpe How to? copy / exclude Support 2
fpefpe robocopy -- copy /w Support 8
C copy /w /p prompts for deletion, but ... Support 3
D Fixed Copy Support 1
fpefpe Documentation copy/move using /c or /u Support 2
samintz WAD Copy/append adds a character Support 3
P Simple RegEx copy Support 9
fromano Fixed COPY ... TO ... crashing Support 3
Alpengreis How to? Copy & Paste without linebreak within TCMD Support 13
D COPY returns ERRORLEVEL 2 Support 5
mdwyer TCC 13 COPY: specified network name is no longer available. Support 5
CWBillow Copy a tree Support 17
J junction copy/move handling Support 6
vefatica Fixed COPY /S ftp://... Support 1
C WAD copy /u ftp local with Timeout? Support 5
D How to? Unregister a copy of Take command Support 1
vefatica FTP copy interrupted Support 2
C How to? COPY ftp folder query Support 7
R How to? TCC 16.03: copy a file to the clipboard? Support 10
jadaml Documentation Is COPY realy doesn't work for any HTTP and FTP? Support 3
T TCC control-C copy operation Support 3

Similar threads