Page 1 of 3
FTP - in one batch file?
Posted: 27 Sep 2013 05:36
by Adrianvdh
Hello everyone...
I am having some issues with this batch file...
(
http://www.dostips.com/?t=Batch.FtpBatch)
Code: Select all
set "myvar=%~d0%~p0File v%currentversion%.bat"
@ftp -i -s:"%~f0" >nul 2>nul &goto :EOF
open mywebsite.com
anonymous
anonymous
cd public_html/public
ascii
get "file.bat" "%myvar%"
quit
As you can see I have changed some stuff
But I don't think to make it run without showing the output result code [>nul 2>nul] is working
and how do I use variables as well, I remember when using ftp with 2 batch files, it would echo the directory as a variable.
Thanks
Re: FTP - in one batch file?
Posted: 27 Sep 2013 08:59
by Adrianvdh
Anyone?
Re: FTP - in one batch file?
Posted: 27 Sep 2013 10:40
by aGerman
You can't since ftp.exe doesn't expand environment variables. You can write a temporary ftp script via batch and pass it to ftp.exe.
Regards
aGerman
Re: FTP - in one batch file?
Posted: 27 Sep 2013 11:05
by penpen
If you want to avoid temporary file(s), you could also pipe the needed data to ftp.exe:
Code: Select all
setlocal
set "myvar=%~d0%~p0File v%currentversion%.bat"
(
echo open mywebsite.com
echo anonymous
echo anonymous
echo cd public_html/public
echo ascii
echo get "file.bat" "%myvar%"
echo quit
)|ftp
endlocal
Although i would prefer in this case aGermans solution as this is better for debugging (and should be nearly the same source).
penpen
Re: FTP - in one batch file?
Posted: 27 Sep 2013 11:23
by foxidrive
I just want to comment (again) that anyone who lived through the MS-DOS days knows just how many
temporary files were used back then, and laughs at the youngsters these days who want to avoid using them.
Back then temporary files were created on far slower hard drives (and floppies!!) and with far slower CPUS - and the files weren't an issue. (ok, we *had* to use them too)
Nowadays temporary files are created on super fast SSDs (and swift HDD) and with super quick CPUs - so what's all the fuss over temporary files, I say!
s'funny.
Re: FTP - in one batch file?
Posted: 27 Sep 2013 11:51
by Adrianvdh
Thanks penpen, I will test that in a moment
But how would I check if ftp.exe downloaded the file? I have tried to use this...
Code: Select all
mode 80, 30
@ftp -i -s:"%FTPDown%" & goto :downloadupdatefileFTPcheck
::@ftp -i -s:"%FTPDown%" >nul 2>nul& goto :downloadupdatefileFTPcheck
:checkUpdateWriteFTP
::call :checkupdateps1DownUAC
if exist "%FTPDown%" del "%FTPDown%"
(echo open %updatefileURL%
echo %FTPUser%
echo %FTPPass%
echo ascii
echo get "%updatefilename%" "%newversionupdatefile%"
echo disconnect
echo bye )>>"%FTPDown%"
exit /b
:downloadupdatefileFTPcheck
[color=red]for /f "tokens=*" %%i in ('@ftp -i -s:"%FTPDown%"^|findstr /i "Can't open"')[/color]
if "%errorlevel%"=="0" (goto downloadupdate1 ) else (
if exist "%newversionupdatefile%" (goto searchupdatefile ) else (goto downloadupdate1 ) )
But no luck, any idea? Thanks guys your always helpful
P.S. Sorry about the mess I am just debugging
P.P.S WT FAQ? Why won't phpBB allow me to colour/color stuff?
Re: FTP - in one batch file?
Posted: 27 Sep 2013 15:41
by ShadowThief
Adrianvdh wrote:P.P.S WT FAQ? Why won't phpBB allow me to colour/color stuff?
because the code tag breaks formatting
Re: FTP - in one batch file?
Posted: 27 Sep 2013 15:54
by Adrianvdh
ShadowThief wrote:Adrianvdh wrote:P.P.S WT FAQ? Why won't phpBB allow me to colour/color stuff?
because the code tag breaks formatting
I do not understand?
Re: FTP - in one batch file?
Posted: 27 Sep 2013 16:58
by ShadowThief
testSame BBcode, but the code tag prevents the color tag from being used.
Re: FTP - in one batch file?
Posted: 27 Sep 2013 17:10
by Adrianvdh
Oh ok thanks
. But could e get back to topic? I cannot get penpen's code to work.
Re: FTP - in one batch file?
Posted: 27 Sep 2013 23:27
by foxidrive
Adrianvdh wrote:But how would I check if ftp.exe downloaded the file? I have tried to use this...
There is no simple way to check if a file has completely downloaded - except by capturing the FTP transfer chatter and parsing the result, to see if there is a success message,
or by capturing and parsing the FTP directory listing to get the filesize and then comparing the filesize of the downloaded copy.
Re: FTP - in one batch file?
Posted: 28 Sep 2013 05:29
by Adrianvdh
Can't I just findstr "Can't open" in the output result?
That is the problem I have, and I can't get the code I posted to work. Also penpen's code is not working, how can I do what he did, using variables and not making a ftp script?
Thanks
Re: FTP - in one batch file?
Posted: 28 Sep 2013 06:44
by foxidrive
This doesn't work here with my ftp server and user/pw details.
Code: Select all
@echo off
(
echo open ftp.domain.com
echo myuser
echo mypassword
)|ftp
I get this - but it works if I log in interactively.
User (ftp.domain.com:(none)): Password:
Login incorrect.
Login failed.
Re: FTP - in one batch file?
Posted: 28 Sep 2013 07:16
by Adrianvdh
Same here I also get that
, but it is not what I am looking for. Thanks anyway
Re: FTP - in one batch file?
Posted: 28 Sep 2013 09:30
by aGerman
Code: Select all
@echo off &setlocal
(
echo open ftp.domain.com
echo myuser
echo mypassword
echo disconnect
echo bye
)>"%temp%\test.ftp"
for /f "delims=" %%i in ('ftp.exe -i -s:"%temp%\test.ftp" 2^>^&1 ^| findstr .') do echo %%i
del "%temp%\test.ftp"
pause
... should pipe everything to FINDSTR including error messages. If that works try to modify the FINDSTR portion using
/ic:"Can't open".
Regards
aGerman