Solved my own problem! :hack: here is what I came up with.
1) Install the Safari downloader hack, which allows download of files to /var/mobile/Library/Downloads.
2) Set up a launchd plist file at /Library/LaunchDaemons/com.automation.torrentmover.plist
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>com.automation.torrentmover</string>
<key>ProgramArguments</key>
<array>
<string>/var/mobile/torrentmover.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/var/mobile/Library/Downloads</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>onDemand</key>
<true/>
</dict>
</plist> 3) Create the script /var/mobile/torrentmover.sh
Code:
#!/bin/bash
/bin/echo "START" >> /var/log/torrentmover
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
LOG=/var/log/torrentmover
DEST=username@xxx.xxx.xxx.xxx:/TORRENTDROP/iPhone_`date +%Y%m%d_%H:%M:%S`.torrent
DIR=/var/mobile/Library/Downloads/
FILELIST=`/bin/ls $DIR`
/bin/echo "Change detected in $DIR" >> $LOG
for f in $FILELIST
do
echo " Checking $DIR/$f" >> $LOG
file $DIR/$f | grep -i bittorrent 2>&1 > /dev/null
IS_TORRENT=$?
SUCCESS=-1
if [ $IS_TORRENT -eq 0 ]; then
echo " Torrent file detected" >> $LOG
scp $DIR/$f $DEST 2>&1 >> $LOG
SUCCESS=$?
fi
if [ $SUCCESS -eq 0 ]; then
echo " File sent, removing" >> $LOG
rm $DIR/$f
fi
done
exit
Make that script executable with chmod +x. I have this file owned by root, I don't think it worked when owned by mobile.
4) Install the launchd job:
Code:
launchctl load /Library/LaunchDaemons/com.automation.torrentmover.plist
Now try downloading a .torrent file from mobile Safari, and it should get sent to the destination folder on your server, where you have Transmission or some other torrent client watching the dir for new torrents.
NB I rename the files to iPhone_<date>.torrent because on some torrent sites I would end up with a file called torrent.php. That's why I use 'file' to determine if a file is BitTorrent.
Hope this helps someone else, please let me know your thoughts.
Jon
Bookmarks