Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 22, 2005, 09:07 AM   #1
bunkre
macrumors member
 
Join Date: Mar 2004
newbie: scheduling FTP actions

(I'm really new to applescript)

How hard of a task would it be to write an applescript that will go and grab specific folders from a server via FTP, or even better, schedule it to grab them every week or so? Am I better off scripting an app like Transmit?

My brother is a unix/linux preacher and wants be to us wget, but I don't know **** about command line.
bunkre is offline   0 Reply With Quote
Old Apr 22, 2005, 09:45 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
wget is not good for ftp! It's really for http. I would personally recommend using the command line ftp client. Write a shell script to do whatever you want then schedule with cron.

A basic ftp script would look something like
Code:
#!/bin/sh

ftp servername_or_ip << FTP_EOF
user username password
cd directory_name
get file
FTP_EOF
Replace servername_or_ip, username, password, directory_name and file with the required stuff. If you want to get whole directories (this assumes you have the correct local directories) you need something like

Code:
#!/bin/sh

ftp servername_or_ip << FTP_EOF
user username password
cd directory_name
lcd directory_name
prompt
mget *
FTP_EOF
lcd changes your local directory, prompt turns off prompting, mget is multiple get.

Cron is pretty easy to setup. Do a Google search for that. Save the script somewhere and make it executable (chmod u+x <scriptname>). You may want to add a line to the start of the script (above the ftp) to change the local working directory.

The reason I think this is better is that you don't need to buy Transmit! I don't think AppleScript can do FTP on it's own. If you give me some more details I can write a better script for you.

Edit: Been playing. This is better.
Code:
#!/bin/sh
 
FTP_USER=<USERNAME>
FTP_PASS=<PASSWORD>
FTP_HOST=<HOSTNAME>
 
DIRS='<LIST_OF FILES>'
 
LOCAL_BASE=<LOCAL_DIR>
 
export FTP_USER FTP_PASS FTP_HOST DIRS LOCAL_BASE
 
mkdir -p $LOCAL_BASE
cd $LOCAL_BASE
 
for dir in $DIRS ;\
do \
(\
ftp $FTP_HOST << FTP_EOF\
user $FTP_USER $FTP_PASS\
cd $dir\
lcd $dir\
prompt\
mget *\
FTP_EOF\
)\
;\
done
If you replace the variables (contained in <> above) with the correct details (the list should be space separated, i.e. 'dir1 dir2 dir3') then this will ftp to the given host and copy each of the directories specified to the directory specified in LOCAL_BASE. Note that unless LOCAL_BASE is absolute it will be relative to the current directory. So if your user is called fred setting LOCAL_BASE /Users/fred/Desktop would result in a set of directories on freds desktop.

Last edited by robbieduncan; Apr 22, 2005 at 10:12 AM.
robbieduncan is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Scheduling app James66 iPad Apps 1 Jul 19, 2014 05:57 PM
General: Better DND scheduling? Missjenna Jailbreaks and iOS Hacks 5 Feb 19, 2014 06:26 AM
iPhone: Scheduling Possible? xybadog iOS 6 5 Apr 6, 2013 08:33 AM
EP Scheduling question LincolnAthas Mac Applications and Mac App Store 0 Jun 28, 2012 03:20 PM

Forum Jump

All times are GMT -5. The time now is 11:43 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC