Simple FTP upload script

Instructional HowTos, posted by users. No questions here please.

Moderators: AmigoJack, helios, bbadmin, Bob Hansen, MudGuard

Post Reply
quatermass
Posts: 4
Joined: Sun Aug 20, 2006 7:50 pm
Location: Livingston, UK
Contact:

Simple FTP upload script

Post by quatermass »

Here is my FTP script.

It allows you to open a file from your local copy of your web site and by the simple clicking of a icon in Textpad the file is uploaded to the correct directory on your FTP server.


You need to edit the FTP script to include your details first.

The script is enclosed below. Cut it out and make it a file FTP_UPload.bat

Ok, place the FTP_UPload.bat into a directory thats going to be easy to get to.

Lets say you put it in c:\extras\

Now edit the .bat file with your details.

Look for lines with **. This line will describe what needs to be done to the line below.

There are 6 lines you'll need to edit.


Note: I keep my own FTP files at Z:\FTP_UPLOAD\
and each subdirectory of this is an exact copy of the one on the Internet.
My Script uses this fact to extract the subdirectory info required to put the file you are wishing to upload into the correct FTP directory.




HOW TO PUT THIS SCRIPT INTO USE IN TEXTPAD.

Ok, open Textpad.
Click on 'Configure>Preferences>Tools'
Click on ADD - Program.

A file browser window will open. Locate the FTP_UPLOAD.BAT file and select it.

Click on 'Apply'. You'll see the title appear in the left side and right side.

Single Click on the title on the left pane under Tools.

You can now enter the parameters to run the script on the right pane.

Command: this should contain the full path to the script.

Parameters : $File $UNIXPath

Initial Folder: $FileDir

Ensure you tick the option 'Save all ocuments first' ON.

Take OFF the 'Capture output' option.

Click on OK.

Now to create an icon to click upon.

Right click on any of the icons, say the Save icon.

Choose the Customise option from the menu.

Click on the Commands tab.

Click on the Tools category.

You'll see lots of hammer like icons. Hover over each one in turn and you should see one via a hint pane popup with the name of your script.

Drag this icon to anywhere you want the icon to appear.



Finished.
Now just place a practise file into your local FTP directory,
Open this in Textpad and click on the icon.

It will be uploaded.
Check it is.

That's all there is too it.


Note:
When you first run this, Windows may ask if you wish to unblock the FTP program. This is Windows XPs very own program so unblock it or it wouldn't work.
Also you may wish to check your AV program isn't blocking the running of the ftp.exe file. Some systems like Nortons may.


P.S.
The script will stay open for 20 secs so you can look at its output and see it is working.

If you want to remove this behaviour please remove the line mentioned near the bottom of the scipt.

Have fun. :D




Code: Select all

@ECHO OFF
REM FTPupload for textpad.
REM Version 1.00 Works with Windows XP Pro SP2 and TextPad 4.7.3.
REM
Set file=%1
Set unixpath=%2

REM No real need to alter the line below It points to the location of a temp file this script creates.
REM So it needs write permission. The Temp folder is normally ok.
Set tempfile=%TEMP%\ftp_uploadtemp.tmp

REM ** Set the line below to your local directory root. It should end with a \
Set localdir=Z:\FTP_UPLOAD\


REM ** Set the variable 'length' to the length of your local directory root minus 3
REM Currently this isn't used. But change it anyway. ie Z:\FTP_UPLOAD is 11
Set length=11

REM ** Enter your FTP username below. NO trailing spaces please
Set username=freddie

REM ** Enter your FTP password below. NO trailing spaces please
Set password=mypasswordgoeshere

REM ** Enter your FTP server name below.NO trailing spaces please
Set ftpserver=ftp.server.net

REM ** Enter your FTP directory root path. Note it has a leading / and NO trailing / 
REM   (If you logon to a FTP site with no subdirectory, then simply use '/' )
Set ftpdir=/home/exampleuser/webs

REM ** Replace xx with the value of the length variable. ie in this example 11 
Set remotepath=%unixpath:~xx,199%

ECHO ===========
ECHO   :%remotepath%:


echo open %ftpserver%> %tempfile%
echo %username%>> %tempfile%
echo %password%>> %tempfile%
echo cd %ftpdir%%remotepath%>> %tempfile%
echo ascii>> %tempfile%
echo hash>> %tempfile%
echo send %file%>> %tempfile%
echo quit %file%>> %tempfile%
ftp -s:"%tempfile%"

DEL /Q %tempfile%
REM Remove the line below or add a REM to the start once you're happy it is working.
SLEEP 20

EXIT

Stuart Halliday
MrSnoot
Posts: 1
Joined: Fri Aug 08, 2008 12:35 am

Post by MrSnoot »

Hi,

thanks for that script; however I always get this error:

Code: Select all

ftp> cd /www~22,199
550 /www~22,199: No such file or directory
I also tried it without the 'www' and with different lengths of my directory. The files aren't uploaded to the FTP. But at the end the log always tells me "Prozess erfolgreich beendet." ("Process successfully finished").

Any idea what is wrong?
quatermass
Posts: 4
Joined: Sun Aug 20, 2006 7:50 pm
Location: Livingston, UK
Contact:

Post by quatermass »

Yes, the path you're trying to change to doesn't exist.
Stuart Halliday
Post Reply