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

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

Discussion in 'Support' started by Avi Shmidman, May 6, 2012.

  1. Avi Shmidman

    Joined:
    Feb 23, 2012
    Messages:
    238
    Likes Received:
    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.
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    Doesn't the /J option allow COPY to restart? It would make deleting the partial target file wasteful!
     
  3. Avi Shmidman

    Joined:
    Feb 23, 2012
    Messages:
    238
    Likes Received:
    3
    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?
     
  4. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    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).
     
  5. Avi Shmidman

    Joined:
    Feb 23, 2012
    Messages:
    238
    Likes Received:
    3
    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.
     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    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).
     
  7. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,300
    Likes Received:
    39
    Is /V supported for an FTP copy?
     
  8. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    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
     
  9. Avi Shmidman

    Joined:
    Feb 23, 2012
    Messages:
    238
    Likes Received:
    3
    Thanks, Steve. Your batch file code was very helpful.
     

Share This Page