How can I automate deleting new files from a directory if their ftp transfer was successful?
September 17, 2004 9:47 AM   Subscribe

Calling all Nerds Automation masterminds. I record radio shows on a weekly basis using a hauappage WinTV card in an XP box (I use the Axife frontend). I'm trying to automate my whole process to the point where all I have to do is plug my ipod into my powerbook. I have scripted ftp.exe to send the resultant MP3 files from the XP box to my powerbook once daily. On the powerbook, I have a folder action set to run a script that adds any files that appear to itunes, and then delete the files. The only thing I haven't got my head around is how to automatically delete the files from the XP directory, BUT ONLY if the ftp transfer was successful. Suggestions?
posted by adamkempa to Computers & Internet (6 answers total)
The only way I know to get a reliable confirmation of FTP upload on XP would involve visual basic. Sorry.
Although, could you script it from the Mac end? Run an FTP server on your XP box, have the Mac pull the mp3s down? Then it knows if it got it or not because the file gets created.
posted by SpecialK at 10:24 AM on September 17, 2004

put a 0 byte file on the mac called "finished". ftp your mp3s to the powerbook, and once they're done, bring "finished" over to the XP box.

after ftp.exe runs, if "finished" exists, deleted "finished' and all the mp3s.
posted by taumeson at 10:26 AM on September 17, 2004

SpecialK - that makes sense, for some reason it didn't occur to me to do it the other way around.

Taumeson - that's a good idea. I'd have to write a short program of some sort to test that 'finished' exists (Unless there's an easier way?), but that seems like a decent solution.

These are exactly the sort of tips I was fishing for, thanks!
posted by adamkempa at 10:44 AM on September 17, 2004

Is ftp the only way to connect the two machines? Does Mac do, say, SMB shares? That way it's just a copy from one place to another, and then it's simple to see if the file exists in both places, is the same size, etc.
posted by RustyBrooks at 10:54 AM on September 17, 2004

Further to RustyBrooks' idea, if the XP filesystem can be seen by the Mac either by ftp or by SMB, the script you're talking about writing to look for the 'finished' file is pretty straightforward, as it can be written to run on the Mac.

if [ -f /path/to/files/finished ]
  rm XP files

The 'rm XP files' would either be a series of ftp command or simply 'rm /path/to/XP/files if the XP filesystem can be seen by SMB.
posted by bachelor#3 at 11:12 AM on September 17, 2004

I think there is an easier way, and that involves using your macintosh as the pull rather than the XP box as the push.

Here's how (and I'm doing this off the top of my fingers, so please feel free to correct):

create a folder in your home directory named, 'radioXP' and another named 'radioMac'. Let's suppose your username on the Mac is 'hubbahubba'.

On the XP box, make a folder named RADIOXP and share it with a username and password, lets say they're 'philco' and 'rca'. Let's also suppose your XP box is named 'okiedoke'.

On the Mac, turn on Windows File Sharing in the Sharing Systems Prefs.

On the XP box, save all your files into radioXP.

On the Mac, create this script:

# make the PC's shared folder appear in your home folder
# as radioXP
mount -t smbfs //philco:rca@OKIEDOKE/RADIOXP /Users/hubbahubba/radioXP

# move all the files into the mac side (or into iTunes or
# whatever. mv gets rid of the original
mv /Users/hubbahubba/radioXP/* /Users/hubbahubba/radioMac

# make the share go away
umount /Users/hubbahubba/radioXP
# end of script

Save this script as plain text named copyradiofromxp in your home folder.
Open a Terminal window and do the following:
chmod a+x copyradiofromxp

At this point, you have an executable program that will move all the files, deleting the originals. I would set it up using cron to run when I want it to, but that's not really a trivial thing as it assumes you know vi and cron. I'm assuming since it's executable that you can start it up from AppleScript or wherever.

to make things a little more slick, on the windows side you might want to alter your creation script to create a file named 'working.txt' and delete it when you're done. Then you add these lines after the 'mount' in the above script:

if (-e /Users/hubbahubba/radioXP/working.txt) then
umount /Users/hubbahubba/radioXP
exit 1

posted by plinth at 5:39 PM on September 17, 2004

« Older PC won't boot   |   How sick for a sick day? Newer »
This thread is closed to new comments.