Batch for easy img upload

Soldato
Joined
22 Aug 2005
Posts
8,966
Location
Clydebank
Hi all I made a quick batch to solve a prob that's been bugging me for ages..

Uploading a pic to my ftp and doing the URL for pasting into these forums, for example. This script will resize to 800 px in long dimension if you have imagemagick installed. (you should!, if not download it) otherwise just rem the 2 lines noted.

2 Batch files, required place them both in your %path% and put a send to in your menu to the first one.


Obviously there are a whole bunch of improvements and features could be added but this saves me the hassle of logging into to ftp each time an remebering my password, and then the url etc....

Man, took me longer to write this post than it did the script...


Sample out put
Code:
Processing "C:\Documents and Settings\user\Desktop\20090125\DSC_1076.JPG"
ftp> open upload.ntlworld.com
Connected to upload.ntlworld.com.
220-
220-##################################################################
220-
220-                    Welcome to upload.ntlworld.com
220-
220-##################################################################
220-
220 upload.ntlworld.com FTP server ready
User (upload.ntlworld.com:(none)):
331 Password required for k.malone97.

230 User k.malone97 logged in.
ftp> !:--- FTP commands below here ---
ftp> mkdir test
550 test: File exists
ftp> cd test
250 CWD command successful.
ftp> binary
200 Type set to I.
ftp> put "C:\Documents and Settings\user\Desktop\20090125\\DSC_1076_resized.JP

200 PORT command successful.
150 Opening BINARY mode data connection for DSC_1076_resized.JPG.
226 Transfer complete.
ftp: 247244 bytes sent in 8.59Seconds 28.77Kbytes/sec.
ftp> disconnect
221 Goodbye.
ftp> bye
URL
http://homepage.ntlworld.com/k.malone97/test/DSC_1076_resized.JPG
VBULLITEN
[IMG]http://homepage.ntlworld.com/k.malone97/test/DSC_1076_resized.JPG[/IMG ]


upload_img.bat
Code:
@echo off
REM Image File Upload Script
REM Resizes supplied image file and uploads file to FTP Server and provides
REM URL of uploaded file and Vbulliten output for copy pasting...

REM Expects image as %1

set size=800
SET subfolder=test


ECHO Processing %1
SET img_name="%~1"


REM these next 2 lines if no resize needed
convert %1 -resize %size% "%~dp1\%~n1_resized%~x1"
SET img_name="%~dp1\%~n1_resized%~x1"




CALL ftp_img.bat %subfolder% %img_name%
echo URL
echo http://homepage.ntlworld.com/k.malone97/%subfolder%/%~n1_resized%~x1
REM OR THIS IF no resize. make similar mod below
REM echo http://homepage.ntlworld.com/k.malone97/%subfolder%/%~nx1
echo VBULLITEN
echo [ IMG]http://homepage.ntlworld.com/k.malone97/%subfolder%/%~n1_resized%~x1[/IMG]
PAUSE


ftp_img.bat
Code:
;@echo off
;(for /f "usebackq delims=" %%A in ("%~f0") do call echo.%%A)>"%temp%\%~n0.ftp"
;ftp -i -s:"%temp%\%~n0.ftp"
;GOTO:EOF

open upload.ntlworld.com
[B]user[/B]
[B]password[/B]
!:--- FTP commands below here ---
mkdir %1
cd %1
binary
put %2
disconnect
bye
 
Last edited:
I wrote my first batch file the other day (wasn't big, didn't do much lol).

Just a few questions id you don't mind :

What does the ";" do before e.g. ";@echo off"?
 
I think it comments that line out, but the usual method is prefixing with REM.

it's the eol signifier for the for loop.

There's a little bit of cmd trickery in there to make an ftp script 'executable'

The script is a batch file and ftp script combined, it launches, then reads itself back in (excepting lines with a ; ) and supplies that as the script to ftp.exe.

The benefit is that the ftp script can be custom, ie. using variables that are expanded during the initial for looping.

:: Is the alternative to REM, but I have had that cause problems sometimes.

Here: http://www.dostips.com/DtTipsFtpBatchScript.php

Second example.
 
Last edited:
Back
Top Bottom