AppleScript C Perl Shell Xcode Other

Uploading files to your server while away from home - the easy way

Post Reply
coding / applescript     Views: 4317Prev .. Next
Uploading files to your server while away from home - the easy wayPosted: Thursday, August 18, 2011 [23:47:49] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 357
If you travel a lot (or not, does it matter?) sometimes you need to send some files (images, video, what have you) back home or to your server.
All you have to have is a form on a web server to accept file upload and a small APpleScript application linked with Perl or PHP program to process files.

Here is an AppleScript:

View Codeset AllFiles to ""
tell application "Finder"
set the Afolder to choose folder with prompt "Choose a folder with files to upload"
set a_list to every file in Afolder
repeat with i from 1 to number of items in a_list
set a_file to (item i of a_list)
set fileGet1 to a_file as text
set fileGet to the quoted form of the POSIX path of fileGet1
set AllFiles to AllFiles & fileGet & "|"
end repeat
set my_folder_path to container of (path to me) as text
end tell

set scr_name to the quoted form of the POSIX path of my_folder_path
set FileSent to do shell script ("echo " & quoted form of AllFiles & " | perl " & scr_name & "upload.cgi")
display dialog "Files uploaded: " & "\n__________________\n" & FileSent


and a corresponding Perl script located in the same folder as AppleScript application:

View Code#!/usr/bin/perl
my $list = <STDIN>;
my $brids = 'Apple Safari Browser';
$list =~ s/\'//g;$list =~ s/\W$//;$list =~ s/\/+$//;$list =~ s/\n|\r//g;
my @all = split(/\|/,$list);my $f;my $fname1;my $sndfile;my @fs;my %sent;my $result;my $nof;
foreach $f (@all) {
unless($f || $sent{$f}) {next;}
$sent{$f}=1;
if(-f "$f") {
@fs = split(/\//,$f);$fname1 = pop(@fs);
$sndfile=$f;$sndfile =~ s/^\/+//; $nof++;
$result = `curl -F f=@"/$sndfile" -F fn=$fname1 -k http://YourServer.com/upload.file.cgi`;
if($result =~ m/Upload Successful/) {print "$nof\. $fname1 uploaded\n";}
} else {print "Can not find file $f\n";}
} ## FOREACH END


Script is not perfect but it does the job.

Just save AppleScript as an application and place it in the same folder with Perl or PHP script and move the folder to your Applications.
You can drop the AppleScript icon on a Dock for easy access.

After a day on the field in a hotel just click on your Applescript program, select the folder with taken pictures and go for a nice dinner while your Mac will do the job of uploading files to your server for you. And you'll have a copy of all files in a safe place.There's no place like ~
coding / applescriptPrev .. Next
 
Post Reply
Home - Coding: AppleScript C Perl Shell Xcode Other
Our Telegram Group