I'm having a problem with a batch script that I found on the internet which suits really good. When running from my Windows 7 Professional computer the script works like a charm. It opens a ftp connection to a server, copies all the files contained in the specified folder and deletes the files after copying.
But when running from Windows Server 2012 R2 Standard it won't work anymore.
The output with echo on is listed below.
Can anybody see why this is working on Windows 7 but not on Windows Server 2012?
Thanks in advance!!
Felix
Code: Select all
::FtpMoveHere.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off&setlocal EnableDelayedExpansion
set "Fts=%~n0.Fts" &:: name ftp-script like this file extension=fts
set "Ftl=%~n0.Ftl" &:: name ftp-log like this file extension=log
set "Ftf=%~n0.now" &:: temp folder for files of this run
set "Lcd=%USERPROFILE%\Desktop\movehere" &:: local destination
set "Rcd=movehere" &:: Remote Dir
set "Host=host"
set "User=user"
::set /P Pass=Enter password for Host %Host% User %User% :
set "Pass=pass"
if exist "%Ftf%" RD /Q "%Ftf% >NUL 2>&1
MkDir "%Ftf%"
DEl /Q %Fts% %Ftl% 1>NUL 2>&1
:: create and execute Ftp script to get files
Call :GenScript Get & FTP -v -i -s:"%Fts%" >"%Ftl%"
if errorlevel 1 echo Problem errorlevel %errorlevel% &goto :eof
Type NUL>%FTS%
:: create and execute Ftp script to delete remote files
Call :GenScript Del & FTP -v -i -s:"%Fts%" >>"%Ftl%"
Move "%Ftf%\*" "%Lcd%"
:: do cleanup
::Del /Q "%~n0.f*" >Nul 2>&1
::Pause
goto :eof
:GenScript Action ----------------------------------------
>>%Fts% echo open %Host%
>>%Fts% echo/%User%
>>%Fts% echo/%Pass%
>>%Fts% echo/
>>%Fts% echo cd %Rcd%
>>%Fts% echo/
if /I %1==Get (
>>%Fts% echo lcd %Ftf%
>>%Fts% echo/mget *.*
>>%Fts% echo/
) Else (
for %%A in (%Ftf%\*) do >>%Fts% echo Delete %%~nxA
>>%Fts% echo/
)
>>%Fts% echo bye
>>%Fts% echo/
:: For documentation append script to log file
>>"%Ftl%" echo %time% %1-Script ------------------------------------
Type "%Fts%" >> "%Ftl%"
Goto :eof
::FtpMoveHere.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
Code: Select all
C:\Users\Administrator\Desktop\movehere>echo on & setlocal EnableDelayedExpansion
C:\Users\Administrator\Desktop\movehere>set "Fts=FtpMoveHere2.Fts"
C:\Users\Administrator\Desktop\movehere>set "Ftl=FtpMoveHere2.Ftl"
C:\Users\Administrator\Desktop\movehere>set "Ftf=FtpMoveHere2.now"
C:\Users\Administrator\Desktop\movehere>set "Lcd=C:\Users\Administrator\Desktop\movehere"
C:\Users\Administrator\Desktop\movehere>set "Rcd=movehere"
C:\Users\Administrator\Desktop\movehere>set "Host=host"
C:\Users\Administrator\Desktop\movehere>set "User=user"
C:\Users\Administrator\Desktop\movehere>set "Pass=pass"
C:\Users\Administrator\Desktop\movehere>if exist "FtpMoveHere2.now" RD /Q "FtpMoveHere2.now >NUL 2>&1
Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnungist falsch.
C:\Users\Administrator\Desktop\movehere>MkDir "FtpMoveHere2.now"
Ein Unterverzeichnis oder eine Datei mit dem Namen "FtpMoveHere2.now" existiert bereits.
C:\Users\Administrator\Desktop\movehere>DEl /Q FtpMoveHere2.Fts FtpMoveHere2.Ftl 1>NUL 2>&1
C:\Users\Administrator\Desktop\movehere>Call :GenScript Get & FTP -v -i -s:"FtpMoveHere2.Fts" 1>"FtpMoveHere2.Ftl"
C:\Users\Administrator\Desktop\movehere>echo open host 1>>FtpMoveHere2.Fts
C:\Users\Administrator\Desktop\movehere>echo/user>>FtpMoveHere2.Fts
C:\Users\Administrator\Desktop\movehere>echo/pass>>FtpMoveHere2.Fts
C:\Users\Administrator\Desktop\movehere>echo/1>>FtpMoveHere2.Fts
C:\Users\Administrator\Desktop\movehere>echo cd movehere 1>>FtpMoveHere2.Fts
C:\Users\Administrator\Desktop\movehere>echo/1>>FtpMoveHere2.Fts
C:\Users\Administrator\Desktop\movehere>if /I Get == Get (
echo lcd FtpMoveHere2.now 1>>FtpMoveHere2.Fts
echo/mget *.* 1>>FtpMoveHere2.Fts
echo/1>>FtpMoveHere2.Fts
) Else (
for %A in (FtpMoveHere2.now\*) do echo Delete %~nxA 1>>FtpMoveHere2.Fts
echo/1>>FtpMoveHere2.Fts
)
C:\Users\Administrator\Desktop\movehere>echo bye 1>>FtpMoveHere2.Fts
C:\Users\Administrator\Desktop\movehere>echo/1>>FtpMoveHere2.Fts
C:\Users\Administrator\Desktop\movehere>echo 10:01:41,34 Get-Script ------------------------------------ 1>>"FtpMoveHere2.Ftl"
C:\Users\Administrator\Desktop\movehere>Type "FtpMoveHere2.Fts" 1>>"FtpMoveHere2.Ftl"
C:\Users\Administrator\Desktop\movehere>Goto :eof