Sunday, 3 August 2008

a PHP script to transfer files between iphone and linux/mac computer


# requirement:
# a)the work directory on PC/laptop is /home/cross/iphone, which you should modify to suit your situation.
# b)install php on iphone.

# To transfer file from PC to iphone:
# php trans.php FILETOTRANSFER
# To transfer file from iphone to pc:
# php trans.php -[anything] FILETOTRANSFER

$port_lsbu = 150;
$port_home = 75;

$athome = shell_exec("ifconfig"); // check where are you now.

if (substr($argv[1],0,1)=='-') { // get the first argument, if it starts with '-', then transfer from iphone
if(stristr($athome, '') == FALSE) { // ip address of iphone at home is this, this command can find out where i am.
echo 'from iphone to lsbu pc';
$output = shell_exec("scp ./{$argv[2]} cross@136.148.98.{$port_lsbu}://home/cross/iphone/"); //using scp to transfer.
echo 'from iphone to home laptop';
$output = shell_exec("scp ./{$argv[2]} cross@192.168.1.{$port_home}://home/cross/iphone/");
}else{ // no option, which start with '-'. only what file to transfer.
if(stristr($athome, '') == FALSE) {
echo 'from lsbu pc to iphone';
$output = shell_exec("scp cross@136.148.98.{$port_lsbu}://home/cross/iphone/{$argv[1]} .");
echo 'from home laptop to iphone';
$output = shell_exec("scp cross@192.168.1.{$port_home}://home/cross/iphone/{$argv[1]} .");

echo $output;
echo "done!";

No comments:

My photo
London, United Kingdom

Facebook & Twitter