How do I write and use a batch script for ftp in Mac OS X


From the terminal in Mac OS X (10.5), I want to carry out several FTP commands without having to wait for each sequential upload - i.e. I want some way of telling the FTP prompt to carry out a list of sequential commands.

These are

1) append /Users/Desktop/MyVid1.flvab MyVid1.flvaa
2) append /Users/Desktop/MyVid1.flvac MyVid1.flvaa
3) append /Users/Desktop/MyVid1.flvad MyVid1.flvaa
4) append /Users/Desktop/MyVid1.flvae MyVid1.flvaa

Each file being uploaded (appended) is 100MB so ideally I want my ftp prompt to sequentially go through the above 4 steps overnight. This will save me waiting 30 minutes or so and then typing in the next 'append' statement.

Is there any way of putting a list of ftp commands in say a txt file and then getting the ftp prompt to execute these steps one by one?

Please help... I have over 3GB of film to upload in this manner and I'm hoping there's an easy way to do this (PS. I'm appending because the server times out on uploads above 100MB and I have no access to change this)

I'm waiting for your help.... please hurry!


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

just use the FTP built-in commands

$cd /Users/Desktop/YourFileStorage/
220 Your FTP Server
230 User Logged in
Remote system type is UNIX.
Using binary mode to transfer files.
220 set to type I
Interactive mode off.
ftp>mput *.flvaa

It will upload all your files in sequence.

JamesFrogAuthor Commented:
... the first command need to UPLOAD (put) MyVid1.flvaa


the following files need to be APPENDED sequentially to MyVid1.flvaa

.. with the code above, all files will be uploaded but then there's no way of APPENDING them on the server..

The Actual sequence needs to be

1) put (upload) MyVid1.flvaa
2) append /Users/Desktop/MyVid1.flvab MyVid1.flvaa
3) append /Users/Desktop/MyVid1.flvac MyVid1.flvaa
4) append /Users/Desktop/MyVid1.flvad MyVid1.flvaa
5) append /Users/Desktop/MyVid1.flvae MyVid1.flvaa

The above must happen sequentially. I.e

1) file uploads, and ONLY when completed go to 2) etc...
Okay then define a macro

like so

ftp> macdef
(macro name) reappend
Enter macro line by line, terminating it with a null line.
put orig
append stuff1 orig
append stuff2 orig
append stuff3 orig

run the macro like so

this will run those commands in sequence.

10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

as you can see I call the macro up by using a $
JamesFrogAuthor Commented:
This is all new to me so please clarify (as it looks good!)

At the ftp prompt is type in (if the macro was called james)

macdef (james) reappend
put MyVid1.flvaa
append MyVid1.flvab MyVid1.flvaa
append MyVid1.flvac MyVid1.flvaa
append MyVid1.flvad MyVid1.flvaa

when I've typed this in, how do I get back to the


prompt to execute the macro?


Not quite

this is exactly what you type: (macro name) is a prompt <enter> is just hitting the return key without typing.
--cut here--

ftp>macdef <enter>
(macro name) reappend
put MyVid1.flvaa
append MyVid1.flvab MyVid1.flvaa
append MyVid1.flvac MyVid1.flvaa
append MyVid1.flvad MyVid1.flvaa

--cut here--

I just selected reappend as a good name that does not clash with anything.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JamesFrogAuthor Commented:
thanks for all your help.. one more thing...

What is a 'null line' and how do I create it. From the above I can see it's not enter - so what is it and how do I create one?


just hit the enter key, thats the null line
JamesFrogAuthor Commented:
That's way cool! - it works a treat... now I can rack up several gigs of uploads and HAVE A LIFE for a few days!!!

Thanks so much for your help!

Best WIshes

JamesFrogAuthor Commented:
You may want to flag it as an accepted solution.
JamesFrogAuthor Commented:
Done. Very much appreciated.
Have fun uploading :-)
JamesFrogAuthor Commented:
.. sorry - seems to be a problem...

I have FTP'd into the server to the folder where I want my macro to run


ftp> macdef
(macro name) james
Enter macro line by line, terminating it with a null line
put /Users/Jadmin/Desktop/temp\ append/Seminar1.flvaa


What I get is

put /Users/Jadmin/Desktop/temp\ append/Seminar1.flvaa
local: /Users/Jadmin/Desktop/temp\ append/Seminar1.flvaa
ftp: local: /Users/Jadmin/Desktop/temp: No such file or directory

For some reason the put doesn't start as it seems to want to ftp to my Desktop temp folder as opposed the the ftp server that I'm logged in to ..

Please help again!

JamesFrogAuthor Commented:
Sorry, please ignore the above comment - I wasn't cd's into the correct directory of the video files before ftp'ing

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Server Software

From novice to tech pro — start learning today.