FTP batch top move (append) to a single remote filename

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
MFOSDICK
Posts: 2
Joined: 17 Sep 2010 08:32

FTP batch top move (append) to a single remote filename

#1 Post by MFOSDICK » 17 Sep 2010 09:40

I am attempting to create an export batch file that will FTP several small .txt files to a single file on a remote ftp server. I created a batch file that seems to work in testing although I have concerns with loosing data if the batch runs and the ftp is unavailable. Is there a better way to script this?

The .txt files are named based on the date/time eg. 083010081040.txt and are exported on a scheduled basis. I was looking for something to add to windows scheduler but was concerned about data lose.


Any assistance would be welcome.

Thank you - Matt

:Archive
@ECHO '
@ECHO ' Beginning Archive Process
@ECHO '

IF NOT EXIST .\ARCHIVE MD .\ARCHIVE
COPY *.TXT .\ARCHIVE
COPY *.TXT TKTULOADP.DAT

:FTP
@ECHO '
@ECHO ' Beginning FTP Transfer Process
@ECHO '

> DataTran.ftp ECHO user
>>DataTran.ftp ECHO ftppass
>>DataTran.ftp ECHO hash
>>DataTran.ftp ECHO append TKTULOADP.DAT OSMDCSDB\TKTULOADP
>>DataTran.ftp ECHO quit

@ftp -v -i -s:DataTran.ftp 10.20.30.13
echo %errorlevel%
pause

IF %errorlevel% > 0 GOTO EOF
DEL *.txt
:EOF

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: FTP batch top move (append) to a single remote filename

#2 Post by ghostmachine4 » 17 Sep 2010 18:17

if your FTP server is unavailable, the FTP client will complain without uploading your file. No problem there. If you want to check whether its being uploaded correctly, you can send a dummy file after its uploaded. Then do a check to see if that dummy file exists after the upload.

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: FTP batch top move (append) to a single remote filename

#3 Post by amel27 » 17 Sep 2010 22:47

MFOSDICK wrote:I have concerns with loosing data if the batch runs and the ftp is unavailable

It is bad idea using native FTP client for appending data. It does not support restarting upload/download if connect interrupted during file copying. Only whole file copy recommend OR using 3'd party ftp clients (for example cURL). Furthermore ERRORLEVEL always =0, because last FTP command (bye) successfull.

Code: Select all

@Echo Off

Call :ARH||(Echo Error copy files!& Exit /B 1)
Call :FTP||(Echo Error put file on FTP!& Exit /B 2)
::--
Exit /B 0

:ARH
::--
Echo '
Echo ' Beginning Archive Process
Echo '

If Not Exist .\ARCHIVE MD .\ARCHIVE
If Not Exist TKTULOADP.DAT Type Nul >TKTULOADP.DAT

Copy *.TXT .\ARCHIVE
Copy /B TKTULOADP.DAT + *.TXT TKTULOADP.DAT|| Exit /B 1
DEL *.TXT
::--
Exit /B 0

:FTP
::--
Echo '
Echo ' Beginning FTP Transfer Process
Echo '

> DataTran.ftp Echo user
>>DataTran.ftp Echo ftppass
>>DataTran.ftp Echo put TKTULOADP.DAT OSMDCSDB\TKTULOADP
>>DataTran.ftp Echo quit

FTP -v -i -s:DataTran.ftp 10.20.30.13|| Exit /B 1
::--
Exit /B 0

MFOSDICK
Posts: 2
Joined: 17 Sep 2010 08:32

Re: FTP batch top move (append) to a single remote filename

#4 Post by MFOSDICK » 18 Sep 2010 13:01

Thank you Amel27! I will test out your work and look into cURL.

Post Reply