Re: FTP Transfer
- From: Tom Lavedas <tglbatch@xxxxxxx>
- Date: Fri, 25 Jul 2008 11:57:15 -0700 (PDT)
On Jul 25, 9:34 am, "Jorge Silva" <jorgesilva...@xxxxxxxxxxx> wrote:
basically what i'm looking for is something like this
ftpusername
ftppassword
bin
prompt
lcd "C:\Srv\Output"
put FileNAme000
IF FILE TRANSFER = SUCCESS THEN !move FileNAme000 ..\Backup\Output
But the command isn't this what should be in this case?
--
I hope that the information above helps you.
Have a Nice day.
Jorge Silva
MCSE, MVP Directory Services
"Jorge Silva" <jorgesilva...@xxxxxxxxxxx> wrote in message
news:OdtcAll7IHA.3976@xxxxxxxxxxxxxxxxxxxxxxx
Hi McKirahan thank you for your response,
This is a batch file and it runs every 5 minutes, the problem is if the
connection fails for some reason the move is still performed and it
shouldn't be, if for some reason the connection fails the batch should
retry in the next 5 minutes and so on, so the objective is, if the file
was trasnferred successfully then move, otherwise cancel the move
operation. Heres the Bach File:
<---------------------------------------------------->
@ECHO OFF
IF EXIST "c:\batch\FileList.txt" goto CancelOperation
REM Change Directory where the files to be transferred are.
cd "C:\Srv\Output"
REM Copy the name of the files in the directory
REM "C:\Srv\Output" to the FileList.txt
dir /b > "c:\batch\FileList.txt"
REM Move to the directory where the batch file and FileList.txt are
cd "c:\batch"
REM Load information into the FtpScr.txt that will be used by
REM the command "ftp -s:FtpScr.txt 000.000.000.000" at the end of this
batch file.
echo ftpusername> FtpScr.txt
echo ftppassword>> FtpScr.txt
echo bin>> FtpScr.txt
echo prompt>> FtpScr.txt
REM lcd to change to the directory where the
REM files to be transferred are.
echo lcd "C:\Srv\Output">> FtpScr.txt
REM Where it loads the information from the files from the
REM FileList.txt to the FtpScr.txt adding the !put and the !move
For /f "tokens=1" %%a in (c:\batch\FileList.txt) do (
If /i "%%a" NEQ "All" (
echo put %%a>> FtpScr.txt
echo !move %%a ..\Backup\Output>> FtpScr.txt
)
)
echo quit>> FtpScr.txt
REM Inserts the date and time into FtpLog.txt
echo. |date /T>> FtpLog.txt
echo. |time /T>> FtpLog.txt
REM Begins the transfer and logs the information in the FtpLog.txt
ftp -s:FtpScr.txt 000.000.000.000>> FtpLog.txt
del c:\batch\FileList.txt
:CancelOperation
<---------------------------------------------------->
The FtpScr.txt looks like
<---------------------------------------------------->
ftpusername
ftppassword
bin
prompt
lcd "C:\Srv\Output"
put FileNAme000
!move FileNAme000 ..\Backup\Output
put FileNAme001
!move FileNAme001 ..\Backup\Output
put FileNAme002
!move FileNAme002 ..\Backup\Output
quit
<---------------->
<---------------------------------------------------->
Thank you again.
The only way I can think to do this in batch is to break this up into
separate transfer scripts, something like this ...
@ECHO OFF
IF EXIST "c:\batch\FileList.txt" goto CancelOperation
REM Change Directory where the files to be transferred are.
cd "C:\Srv\Output"
REM Copy the name of the files in the directory
REM "C:\Srv\Output" to the FileList.txt
dir /b > "c:\batch\FileList.txt"
REM Move to the directory where the batch file and FileList.txt are
cd "c:\batch"
REM Where it loads the information from the files from the
REM FileList.txt to the FtpScr.txt adding the !put and the !move
For /f "tokens=1" %%a in (c:\batch\FileList.txt) do (
If /i "%%a" NEQ "All" (
REM Load information into the FtpScr.txt that will be used by
REM the command "ftp -s:FtpScr.txt 000.000.000.000" at the end of this
batch file.
echo ftpusername> FtpScr.txt
echo ftppassword>> FtpScr.txt
echo bin>> FtpScr.txt
echo prompt>> FtpScr.txt
REM lcd to change to the directory where the
REM files to be transferred are.
echo lcd "C:\Srv\Output">> FtpScr.txt
echo put %%a>> FtpScr.txt
echo quit>> FtpScr.txt
REM Begins the transfer and logs the information in the FtpLog.txt
ftp -s:FtpScr.txt 000.000.000.000>> tmpFtpLog.txt
:: Checks progress
find "226 Transfer complete." > nul
type FtpLog.txt >> FtpLog.txt
if not errorlevel 1 (
move %%a ..\Backup\Output >> FtpLog.txt
) else (
REM Inserts the date and time into FtpLog.txt when xfer fails
echo. ------ Ended --- %date% %time% --->> FtpLog.txt
goto :EOF % uses predefined system label for end-of-file %
)
)
)
REM Inserts the date and time into FtpLog.txt
echo. ------ Ended --- %date% %time% --->> FtpLog.txt
del c:\batch\FileList.txt
:CancelOperation
This approach sends one file, checks that it was transfered correctly
and them moves that file to backup. If the transfer fails it stops
transferring files.
Of course, that's the logic, but I didn't have a good way to test it
to be certain there isn't a syntax error or that I had left out some
bit. You'll have to do the debugging in this case.
Also note that this creates a lot more 'trash' in the log file. It
could be filtered, but that might be complicated - I haven't thought
about that part. The other approach would be to send the output of
the FTP to the bit-bucket and create your own progress statements with
ECHO.
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
.
- Follow-Ups:
- Re: FTP Transfer
- From: Jorge Silva
- Re: FTP Transfer
- References:
- FTP Transfer
- From: Jorge Silva
- Re: FTP Transfer
- From: McKirahan
- Re: FTP Transfer
- From: Jorge Silva
- Re: FTP Transfer
- From: Jorge Silva
- FTP Transfer
- Prev by Date: Re: script to unmap and remap network drives
- Next by Date: Re: Error: Expected statement
- Previous by thread: Re: FTP Transfer
- Next by thread: Re: FTP Transfer
- Index(es):
Relevant Pages
|