I need to upload via FTP some files (not all) from a folder to a remote server.
I coded the following which performs the wildcard match, but I think I am missing something to FTP the resulting files.
Remark: the problem is not to upload the folder (which is relatively simple), but to exclude some entries from the given folder and upload all other files.
I was successful in excluding those files and keep the rest, but I can't find the way to upload the latter.
In particular, mput cmd seems to not work with the input filename. Why ?
I want to focus on this question: how can I feed the FTP cmds to upload each resulting file from the above filtering ?
echo off
setlocal enabledelayedexpansion
FOR /R localfolder %%F IN (*.*) DO (
set fname=%%~nF
set ext=%%~xF
set filename=!fname!!ext!
set subfname=!fname:~0,4!
IF NOT "!subfname!" == "idat" (
echo ftp
echo open ftp.something.it
echo ftpuser
echo ftppass
echo lcd localfolder
echo cd remotefolder
echo binary
echo mput !filename!
echo disconnect
echo bye
)
)
pause
This is the solution, I was nearly close to it: just fill-in an external batch .bat file with ftp commands and then call this file at the end of each loop. Delete it and start again with the next entry on the list.
p.s.: for any further usage, beware of trimming any blank spaces before >> operator, as shown below.
#echo off
setlocal enabledelayedexpansion
FOR /R localfolder %%F IN (*.*) DO (
set fname=%%~nF
set ext=%%~xF
set filename=!fname!!ext!
set subfname=!fname:~0,4!
IF NOT "!subfname!" == "idat" (
echo open ftp.something.it>> ftp.cmds.bat
echo username>> ftp.cmds.bat
echo password>> ftp.cmds.bat
echo lcd localfolder>> ftp.cmds.bat
echo cd remotefolder>> ftp.cmds.bat
echo binary>> ftp.cmds.bat
echo mput !filename!>> ftp.cmds.bat
echo disconnect>> ftp.cmds.bat
echo bye>> ftp.cmds.bat
ftp -i -s:ftp.cmds.bat
del ftp.cmds.bat
)
)
Next script could help. Read List of FTP commands for the Microsoft command-line FTP client
#ECHO OFF
SETLOCAL EnableExtensions EnableDelayedExpansion
set "localfolder=D:\test\31441809\root" change
set "lcd-folder=%localfolder%"
set "excludeFile=nico" change to `idat`
set "ftpscript=%temp%\35574454ftp.dat" change
(
echo open ftp.something.it
echo user ftpuser
echo ftppass
echo binary
echo cd remotefolder
echo lcd %lcd-folder%
FOR /R %localfolder% %%F IN (*.*) DO (
set "fname=%%~nF"
set "ext=%%~xF"
set "filename=!fname!!ext!"
set "subfname=!fname:~0,4!"
IF /I NOT "!subfname!"=="%excludeFile%" (
if /I not "!lcd-folder!\"=="%%~dpF" (
rem change local directory only if necessary
set "lcd-folder=%%~dpF"
set "lcd-folder=!lcd-folder:~0,-1!" remove trailing backslash
echo lcd !lcd-folder!
)
echo put !filename!
)
)
echo disconnect
echo bye
)>"%ftpscript%"
type "%ftpscript%"
pause
ftp -i -n -s:"%ftpscript%"
Sample output:
d:\bat> D:\bat\SO\35574454.bat
open ftp.something.it
user ftpuser
ftppass
binary
cd remotefolder
lcd D:\test\31441809\root
put JohnDoe.txt
lcd D:\test\31441809\root\Ian-ionescu
put Ian-ionescuY.txt
lcd D:\test\31441809\root\John-doe
put John-doe.txt
put John-doeA.txt
lcd D:\test\31441809\root\Nicola-sheperd
put SheperdNicola.txt
lcd D:\test\31441809\root\Sara-smith
put Sara-smith.txt
put Sara-smithZ.txt
disconnect
bye
Press any key to continue . . .
ftp> open ftp.something.it
Connected to www.something.it.
220 FTP Server ready.
ftp> user ftpuser
331 Password required for ftpuser.
etc.etc.
Related
I am trying to make a batch script that moves a file into a startup folder and I want to make it universal
Currently I have this but I want to make it work on any user's computer (C:\users\USERNAME)
Here is the code
#echo off
color A0
echo Startup...
echo Startup..
echo Startup.
echo Startup
echo Startup.
echo Startup..
echo DONE
echo your name is %name%
move C:%user%\Desktop\Directory 1\dile.txt C:%user%\Desktop\Directory 1\file folder 1
:end
cmd /k
The file is called dile.txt located in a folder called Directory 1 on the desktop and I want to make it move to a folder called file folder 1 inside the Directory 1 folder. Is there a way to do this while making it work on anyone's computer?
%USERNAME% can be used to grab the active user account. Try something like this. Make sure to enclose paths in quotes when folders have spaces in their names.
#echo off
color A0
echo Startup...
echo Startup..
echo Startup.
echo Startup
echo Startup.
echo Startup..
echo DONE
echo your name is %USERNAME%
move "C:\Users\%USERNAME%\Desktop\Directory 1\file.txt" "C:\Users\%USERNAME%\Desktop\Directory 1\file folder 1\"
:end
cmd /k
Just for the sake of providing something a little bit different:
#Echo Off & SetLocal EnableExtensions
Set /P "=Startup . " 0< NUL
For /L %%G In (1,1,5) Do (Set /P "=. " 0< NUL
%SystemRoot%\System32\PATHPING.EXE 127.0.0.1 -n -q 1 -p 500 1> NUL)
Echo(&Echo Your name is %UserName%
%SystemRoot%\System32\Robocopy.exe "%UserProfile%\Desktop\Directory 1" "%UserProfile%\Desktop\Directory 1\file folder 1" "dile.txt" /Mov 1> NUL 2>&1
Pause
This uses some animated text, %UserProfile%, instead of C:\Users\%UserName%, and robocopy instead of Move. Using RoboCopy, allows for the creation of your destination directory, if it does not already exist.
I am trying to setup a batch script which can connect to a set of servers and execute start script. Since there is a password getting saved in the commands.txt file. I need to delete it after the execution of start on remote servers. But that del command gets executed before everything and which is causing issues for the loop and errors out that commands.txt file is missing. Not sure how thats getting executed before the loop when its put after the loop. How can I fix this?
Below is the code I am trying.
#echo off
Echo Please enter your password in the popup window and then press enter
set tempbat="%temp%\p.cmd"
REM Create temporary batch file to make popup window for entering password 'masked'
echo mode 20,1 >%tempbat%
echo color EF >>%tempbat%
echo Title Enter Password >>%tempbat%
echo setlocal enabledelayedexpansion >>%tempbat%
echo set /p Pass= >>%tempbat%
echo echo !pass!^>"%temp%\pass.txt" >>%tempbat%
echo exit >>%tempbat%
echo exit >>%tempbat%
start /wait "" %tempbat%
set /p Password=<"%temp%\pass.txt"
#echo echo %password% ^| sudo -S -u x0ats echo startup.sh start>>
%cd%\commands.txt
#echo read>> %cd%\commands.txt
for /f "delims=" %%a in (%cd%\serverlist.txt) DO (
Start PuTTY username#%%a -pw %password% -m "%cd%\commands.txt"
)
del %cd%\commands.txt}
There are a few issues in your CMD script, but most specifically, as I mentioned above you are not putting double quotes around paths.
Additionally you were adding spaces to the ends of all of your line sin the bat file but that will cause you to collect the wrong PW, you also didn't delete your temp bat file or password file after the fact.
It seems like a bit of trouble to go through just to pop up a separate window, you could forgo creating a second batch file and call a sub function instead by making your script support cmd line arguments.
In Any case this should work more as you expect:
#ECHO OFF
ECHO.Please enter your password in the popup window and then press enter
SET "_TempBat=%temp%\p.cmd"
SET "_PWFile=%temp%\pass.txt"
SET "_CMDs=%cd%commands.txt"
REM Create temporary batch file to make popup window for entering password 'masked'
ECHO.SETLOCAL>"%_TempBat%"
REM ECHO.ECHO OFF >"%_TempBat%"
ECHO.mode CON COLS=42 LINES=1 >"%_TempBat%"
ECHO.color CF>>"%_TempBat%"
ECHO.Title Enter Password >>"%_TempBat%"
ECHO.SET /p "_Pass=Enter Password: " >>"%_TempBat%"
ECHO.ECHO.%%_pass%%^>"%_PWFile%">>"%_TempBat%"
ECHO.exit>>"%_TempBat%"
ECHO.exit>>"%_TempBat%"
START /wait "" "%_TempBat%"
DEL /F /Q "%_TempBat%"
IF NOT EXIST "%_PWFile%" (
"%_PWFile%" Not Created!
) ELSE (
FOR /F "Tokens=*" %%A IN ('TYPE "%_PWFile%"') DO (
SET "_PW=%%A"
DEL /F /Q "%_PWFile%"
)
)
#ECHO.ECHO.%_PW% ^| sudo -S -u x0ats ECHO.startup.sh start>> "%_CMDs%"
#ECHO.read>> "%_CMDs%"
for /f "delims=" %%a in ('Type "%_CMDs%"') DO (
Start PuTTY username#%%a -pw %_PW% -m "%_CMDs%"
)
Pause
DEL /F /Q "%_CMDs%"
ALSO I changed the colors you chose Bright Yellow on Bright right is hardly readable, I used Bright white on Bright Red. oh and I also added an Echo Off into your second script because again that was not helpful to have all the extra stuff in there
Also I looked at this and noticed that you were not going to get the PW saved in the PW file so I fixed that by using %% so that the first % will get stripped off.
i would like to see if its possible to echo to an image like you can echo to a file:
echo Hello World! >>"%cd%/test.txt
Like this:
echo (base64 code) >>"%cd%/image.jpg"
what is even wrong with this?
it creates a jpeg file but it gives me the error that it can't be opened.
(probably of its code structure)
I checked it with the base64 to image converter and there is nothing wrong.
Why doesn't it create an image?
This batch file Certutil_B64_Encoding_Files.bat can let you to drag and drop any file like a jpg or png or any file else and generate another batch file with the encoded file inside, So, when you execute it, the file will be decoded and generated to the original.
Just save this code on your notepad or on notepad++ or on any text editor as :
Certutil_B64_Encoding_Files.bat and drag and drop any file over it to be encoded
#echo off
Title Encoding files with CERTUTIL utility by Hackoo 2018
color 0A & Mode 83,3
If "%~1"=="" (
color 0C & Mode 80,3
echo(
echo You must drag and drop a file over this batch script to be encoded !
Timeout /T 5 /nobreak>nul & exit /b
)
#for /f %%i in ("certutil.exe") do if not exist "%%~$path:i" (
echo CertUtil.exe not found.
pause
exit /b
)
set "TempFile=%Temp%\Temp_b64
set "OutputFile=%~nx1_encoded%~x0"
If exist "%OutputFile%" Del "%OutputFile%" >nul 2>&1
echo(
echo Please wait a while ... Encoding "%~nx1" is in progress ...
certutil.exe -f -encode "%~1" "%TempFile%" >nul 2>&1
(
echo #echo off
echo Title My head kinda look like this
echo echo Hello, my name is Kalesheezer, but you can call me Digi Kulamba
echo echo and my head kinda look like this:
echo CERTUTIL -f -decode "%%~f0" "%%Temp%%\%~nx1" ^>nul 2^>^&1
echo Timeout /T 5 /nobreak^>nul
echo Start "%~n1" "%%Temp%%\%~nx1"
echo Exit
)>> "%OutputFile%"
copy "%OutputFile%" /b + "%TempFile%" /b >nul 2>&1
If exist "%TempFile%" Del "%TempFile%" >nul 2>&1
Timeout /T 2 /NoBreak>nul & exit
And here is an example that i tested with my avatar Hackoo.png
Hackoo.png_encoded.bat
#echo off
Title My head kinda look like this
echo Hello, my name is Kalesheezer, but you can call me Digi Kulamba
echo and my head kinda look like this:
CERTUTIL -f -decode "%~f0" "%Temp%\Hackoo.png" >nul 2>&1
Timeout /T 5 /nobreak>nul
Start "Hackoo" "%Temp%\Hackoo.png"
Exit
-----BEGIN CERTIFICATE-----
/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1
c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gOTAK/9sAQwADAgIDAgIDAwMD
BAMDB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aad+1JpPi+ZwljFr
kd00gGP3QkGSPbANbfxh/aEgufhbpOkaTNHL4k1O0Laxd26hfKBLDZlQBvK4zjoM
j6eGWEn2Wyiu4mw6KoqacLasWysf0k6ffW+pWcdzZzR3NtKoaOaFwyOOxBHBFWTk
Gvwm/Z+/bt+KXwGvre2tNYfxD4YjO0aFqrtJCiE5xE2d0Z64wcc8g1+qv7L/AO2l
4M/aYsmtrLfofieCPzLjRbxgz7R1eJxgOufoR3ArrRxOPKfil4s8U6h431a/8R6/
qEmp6rqM7TXFxOfmkc8Z/wAAOABgVwF9O00p2AKBwPVf8K3b/TxZ26HeXkBBd2Pf
oMDsMVz9s3nk8cE96k6FpqT6aWWO4hY9VyOe3f8AnTDaqAcKARyMCtO10/eQyqM9
DVyTTxFC52YIU81ViucyUswsKEDHrQl0VtmtQp3Mcs2eK3be1BijXAPGOlVbqzEU
hOwc9aklSZWs4WVwCCMeleh/DDx3q/wu8aaP4r0Cf7PqmmziaM87Txgqw7qykqR6
E157DqAs5VDruQnGe4rorF4riISRNuU1orGT11P/2Q==
-----END CERTIFICATE-----
Further Reading
An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
certutil - Dump and display certification authority (CA) configuration information, configure Certificate Services, back up and restore CA components, verify certificates, key pairs or certificate chains.
You can use the command HEX2PNG.EXE to reconstruct a text file to an image.
Example :
smiley.txt
--------------#####--------------
-----------###.....###-----------
---------##...........##---------
-------##...............##-------
------#...................#------
-----#.....................#-----
----#...####........#####...#----
----#..####c#......####cc#..#----
---#..#####cc#....#####ccc#..#---
---#..#####cc#....#####ccc#..#---
--#...####ccc#....####cccc#...#--
--#..#cccccccc#..#ccccccccc#..#--
--#..#cccccccc#..#ccccccccc#..#--
-#...#cccccccc#..#ccccccccc#...#-
-#...##########..###########...#-
-#.............................#-
-#.............................#-
-#.............................#-
--#..#######################..#--
--#..#aaaaaaaaaaaaaaaaaaaaa#..#--
--#..#aaaaaaaaaaaaaaaaaaaaa#..#--
---#..#aaaaaaaaaaaaaaaaaaa#..#---
---#..#aaaaaaaaaaa;;;;aaaa#..#---
----#..#aaaaaaaaa;;;;;;aa#..#----
----#...#aaaaaaa;;;;;;;;#...#----
-----#...##aaaa;;;;;;;##...#-----
------#....###;;;;;###....#------
-------##.....#####.....##-------
---------##...........##---------
-----------###.....###-----------
--------------#####--------------
To build the image you have to replace each kind of char with an hexa color and then run hex2png.exe against the smileuout.txt :
In this case
The char [c] with white [FFFFFFFF]
The char [a] with maroon [103E66FF]
The char [.] with yellow [00EAFFFF]
The char [-] with transparent (black + transparent value to 00) [00000000]
The char [#] with black (non transparent) [000000FF]
The char [;] with red [0000FFFF]
This bat will do that :
#echo off
set $fichier=smiley.txt
set $taille=33;31
set $TotPix=1023
set $Fsortie=smiley.png
:::Crátion de la première ligne de sortie.txt (width_pixel;Height_pixel;Name_of_file.PNG;Total_number_of_pixel)
echo %$taille%;%$Fsortie%;%$TotPix%>SmileyOut.txt
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('type %$fichier%') do (echo %%a
set $ligne=%%a
set $ligne=!$ligne:c=FFFFFFFF !
set $ligne=!$ligne:a=103E66FF !
set $ligne=!$ligne:.=00EAFFFF !
set $ligne=!$ligne:-=00000000 !
set $ligne=!$ligne:#=000000FF !
set $ligne=!$ligne:;=0000FFFF !
set /a $c+=1
for %%b in (!$ligne!) do (echo %%b>>SmileyOut.txt))
endlocal
hex2pngV1.3.exe smileyout.txt
del smileyout2>nul
start smiley.png
The output will be this nice smiley :
The structure of the file smiley.txt is very important !
This vars must be setted correctly or the image will be corrupted :
$fichier=smiley.txt
$taille=33;31 => width;height of the output file each char is one pixel
$TotPix=1023 => The total of pixel (width * height)
$Fsortie=smiley.png => the name of the output PNG
The command PNG2HEX will do exactly the contrary an generate a txt file from an image !
I need to download 300 images from site.com/folder/ using the following format: 1.png, 2.png ... 300.png
Is there a way to do this inside a batch file or using the command prompt?
Wth curl like this:
curl -o "#1.png" http://example.com/folder/[1-300].png
Here is an example to download some batch codes from a file that can be created by this script if not exist, and of course you can add or modify what you want of urls in this file !
You can add your urls in the text file named Urls.txt
Firstly, the script check for the text file named Urls.txt if exist in same location where this batch is executed and read from it the urls line by line to download them !
So, if you want to change those urls to yours, just change it from the text file Urls.txt not from the batch, i mean you can create a text file and name it to Urls.txt and put what you want as urls on this file line by line of course and let the script do its job
#echo off
Mode 110,3 & color 0A
Title Download file from web using powershell and batch by Hackoo 2017
Set "List_Urls_File=Urls.txt"
If not exist "%List_Urls_File%" Call :Create_Urls_File
Setlocal enabledelayedexpansion
#For /f "delims=" %%a in ('Type "%List_Urls_File%"') do (
Set "URL=%%a"
Rem we set the Filename from the variable !url!
#for %%# in (!url!) do ( set "File=%%~xn#" )
Rem Check if the file name contains a dot "."
Rem If not we increment the counter +1 for file to be download
ECHO !File! | FIND /I ".">Nul 2>&1
If "!errorlevel!" NEQ "0" (
Set /a Count+=1
cls & echo(
echo Downloading file "File-!Count!.bat" from URL : "!URL!"
Call :BalloonTip 'information' 10 '"Downloading File-!Count!.bat"' "'Please wait... Downloading File-!Count!.bat....'" 'info' 4
Call :Download "%%a" "File-!Count!.bat"
) else (
cls & echo(
echo Downloading file "!File!" from URL : "!URL!"
Call :BalloonTip 'information' 10 '"Downloading !File!"' "'Please wait... Downloading !File!....'" 'info' 4
Call :Download "%%a" "!File!"
)
)
Explorer "%~dp0" & exit
::*********************************************************************************
:Download <url> <File>
Powershell.exe -command "(New-Object System.Net.WebClient).DownloadFile('%1','%2')"
exit /b
::*********************************************************************************
:Create_Urls_File
(
echo https://pastebin.com/raw/XvyhRzT6
echo https://pastebin.com/raw/QqnZ0MjQ
echo https://pastebin.com/raw/tHsKw15V
echo https://pastebin.com/raw/VCnTbLB6
echo https://pastebin.com/raw/3zUTrWUz
echo https://pastebin.com/raw/31auQeFz
echo https://pastebin.com/raw/xF0uXThH
echo https://pastebin.com/raw/uzsGQD1h
echo https://pastebin.com/raw/3TmVYiZJ
echo https://pastebin.com/raw/Ntc8SZLU
echo https://pastebin.com/raw/jnpRBhwn
echo https://www.virustotal.com/static/bin/vtuploader2.2.exe
echo http://devbuilds.kaspersky-labs.com/devbuilds/KVRT/latest/full/KVRT.exe
)>"%List_Urls_File%"
exit /b
::*********************************************************************************
:BalloonTip $notifyicon $time $title $text $icon $Timeout
PowerShell ^
[reflection.assembly]::loadwithpartialname('System.Windows.Forms') ^| Out-Null; ^
[reflection.assembly]::loadwithpartialname('System.Drawing') ^| Out-Null; ^
$notify = new-object system.windows.forms.notifyicon; ^
$notify.icon = [System.Drawing.SystemIcons]::%1; ^
$notify.visible = $true; ^
$notify.showballoontip(%2,%3,%4,%5); ^
Start-Sleep -s %6; ^
$notify.Dispose()
%End PowerShell%
exit /B
::*************************************************************************
Numbered-Files Downloader 1.0
Here is a complete batch script that is doing exactly what you asked for. You don't need to download any executable files, this is 100% batch script and it should works on any (recent) Windows installation.
All you need to do is to edit the _URL variable (Line 11) and replace "example.com/folder..." with the actual URL of the files you want to download. After that, you can run the script and get your files.
Note that in your URL, this string: _NUMBERS_ is a keyword-filter that will be replaced by the incremented numbers in the final download function.
All your downloaded files will be saved in the directory where this script is located. You can choose an other directory by uncommenting the _SAVE_PATH variable (Line 15).
Finally the following variables can be changed to configure the series of numbers:
_START : The file numbers starts with this value.
_STEP : Step between each files.
_END : The file numbers ends with this value.
Leading Zeros
Currently, the counter doesn't support leading zeros.
EX. From Picture_001.jpg to Picture_999.jpg
But otherwise it should work fine for something like this:
EX. From Picture_1.jpg to Picture_999.jpg
I will try to find some time to add this option, it shouldn't be too difficult.
Feel free to modify & enhance this script if you need!
Numbered-DL.cmd
#echo off
setlocal EnableDelayedExpansion
rem STACKOVERFLOW - QUESTION FROM:
rem https://stackoverflow.com/questions/45796990/batch-download-images-from-url-with-for
:VARIABLES
rem WHERE YOU WANT TO SAVE FILES
rem "%~dp0" is a variable for the same folder as this script, so files should be saved in the same folder.
rem If you want to save the downloaded files somewhere else, uncomment the next line and edit the path.
SET "_SAVE_DIR=%~dp0"
rem SET _SAVE_PATH=C:\Folder\
rem DOWNLOAD THIS FILE URL
rem
rem "_NUMBERS_" WILL BE REPLACED BY THE COUNTER
rem CURRENLY IT DOESN'T SUPPORT CHOOSING A NUMBERS OF ZEROS FOR THE COUNTER EX: 001,002,003...
rem BUT IT SHOULDN'T BE TOO HARD TO IMPLEMENT, MAYBE ILL ADD THIS IN THE FUTURE.
rem
rem SET _FILE_URL=https://example.com/folder/_NUMBERS_.png
SET "_FILE_URL=https://cweb.canon.jp/eos/lineup/r5/image/downloads/sample0_NUMBERS_.jpg"
rem FOR THIS EXAMPLE THE SCRIPT WILL DOWNLOAD FILES FROM "sample01.jpg" TO "sample05.jpg"
SET _START=1
SET _STEP=1
SET _END=5
:CMD_PARAMS
IF NOT [%1]==[] SET "_FILE_URL=%1"
IF NOT [%2]==[] SET "_SAVE_DIR=%2"
:PATH_FIX
rem REMOVE THE LAST CHAR IF IT IS "\"
IF [%_SAVE_DIR:~-1%] == [\] SET "_SAVE_DIR=%_SAVE_DIR:~0,-1%"
:DETAILS_DISPLAY
ECHO.
ECHO SCRIPT: Numbered-Files Downloader 1.0
ECHO AUTHOR: Frank Einstein
ECHO.
ECHO.
ECHO INPUTS
ECHO _URL: %_FILE_URL%
ECHO _SAVE_DIR: %_SAVE_DIR%
ECHO.
ECHO _START: %_START%
ECHO _STEP= %_STEP%
ECHO _END= %_END%
ECHO.
ECHO.
CALL :DOWNLOAD_LOOP
ECHO.
ECHO EXECUTION COMPLETED
ECHO.
PAUSE
EXIT /B
:DOWNLOAD_LOOP
SET FINAL_URL=%_FILE_URL%
FOR /L %%G IN (%_START%,%_STEP%,%_END%) DO (
rem REPLACE URL'S KEYWORD WITH NUMBERS
SET NUM=%%G
SET FINAL_URL=%FINAL_URL:_NUMBERS_=!NUM!%
rem CUMSTOM BATCH FUNCTION FOR DOWNLOADING FILES
rem
rem SYNTAX:
rem echo CALL :DOWNLOAD !FINAL_URL!
CALL :DOWNLOAD !FINAL_URL! !_SAVE_DIR!
)
Goto :EOF
rem PAUSE
rem EXIT /B
rem FUNCTIONS
:DOWNLOAD
setlocal
SET "DL_FILE_URL=%1"
SET "DL_SAVE_DIR=%2"
rem EXTRACT THE FILENAME FROM URL (NEED TO FIX THIS PART?)
FOR %%F IN ("%DL_FILE_URL%") DO SET DL_FILE_NAME=%%~nxF
IF "%DL_SAVE_DIR:~-1%" == "\" SET "DL_SAVE_DIR=%DL_SAVE_DIR:~0,-1%"
IF NOT [%2]==[] SET "DL_SAVE_FILE=%DL_SAVE_DIR%\%DL_FILE_NAME%"
IF [%2]==[] SET "DL_SAVE_FILE=%~dp0%DL_FILE_NAME%"
rem :BITSADMIN
ECHO.
ECHO DOWNLOADING: "%DL_FILE_URL%"
ECHO SAVING TO: "%DL_SAVE_FILE%"
ECHO.
bitsadmin /transfer mydownloadjob /download /priority foreground "%DL_FILE_URL%" "%DL_SAVE_FILE%"
rem BITSADMIN DOWNLOAD EXAMPLE
rem bitsadmin /transfer mydownloadjob /download /priority foreground http://example.com/filename.zip C:\Users\username\Downloads\filename.zip
endlocal
GOTO :EOF
try with winhttpjs.bat:
set "baseLink=http://example.org/folder/"
for /l %%a in (1;1;300) do (
winhttpjs.bat "%baseLink%%%a.png" -saveto %%a.png
)
I am using windows batch scripts to run ftp scripts automatically. Where the set of ftp commands I want run is saved in a file.
example:
#echo off
ftp -n -i -s:c:\temp\myftpscriptfile.ftp
I have used the %ERRORLEVEL% syntax to successfully capture error conditions in the batch commands. My challenge is the ftp script command is always returning an ERRORLEVEL of 0 even when the commands inside the script fail.
I am having difficulty figuring out how to have the ftp script actually return or trap when errors occur inside it. It will simply run through the commands blindly and even though i can see the errors echoed on screen I can't capture them as an ERRORLEVEL..
Sample screen shot of trying script which fails to login and then echoing the ERRORLEVEL which shows a zero..
ftp> open fubar.test.com
Unknown host fubar.test.com
ftp> user test test
Not connected.
ftp> ascii
Not connected.
ftp> cd /home/test/dirname
Not connected.
ftp> mput C:\Test\test*.txt
Not connected.
ftp> close
Not connected.
ftp> quit
.0
Use find:
ftp -n -i -s:c:\temp\myftpscriptfile.ftp 2>&1|find "Unknown host">nul
if %errorlevel%==0 (
echo Error!
)
Parse ftp communication using for /F command. Possible approach in next script. Caveat: there supposedly exist some ftp error message(s) not included in given test sequence. Of course, you can test positive ftp messages rather...
#ECHO OFF >NUL
SETLOCAL enableextensions enabledelayedexpansion
set "errsftp=0"
ftp -n -i -s:c:\temp\myftpscriptfile.ftp >c:\temp\31442020.err 2>&1
for /F "tokens=1*" %%G in (c:\temp\31442020.err) do (
rem echo %%G [%%H]
if "%%G"=="ftp>" (
set "line=%%H"
set "errs=0"
) else (
set "reply=%%G %%H"
Call :testreply Unknown host
Call :testreply Connection timed out
Call :testreply Not connected
rem insert next tests here
if !errs! EQU 0 echo !line! =looks OK= !reply!
)
)
echo(
echo :errors total: %errsftp%
ENDLOCAL
goto :eof
:testreply
set "ylper=!reply:%*=!"
if not "!ylper!"=="!reply!" (
echo !line! =ERROR= !reply!
set /A "errs+=1"
set /A "errsftp+=1"
)
goto :eof