- Registriert
- 09.03.07
- Beiträge
- 14
Hallo zusammen,
ich nutze in einem AppleScript den Automator-Baustein "Upload to FTP" von Peter Dekkers. Da ich eine Wordpress-Galerie damit erzeugen möchte, müssen die hochgeladenen Ordner Schreibrechte mit dem Befehl chmod erhalten.
Leider hat Peter diese Option in seinem Baustein nicht berücksichtigt und auch keine Zeit sie einzubauen.
Teil dieses Bausteins ist ein Perl-Skript das die FTP-Kommandos ausführt. Das habe ich versucht zu erweitern. Leider bricht das Automator Script jetzt immer an dem FTP-Baustein ab, ohne eine Fehlermeldung auszugeben aus der man entnehmen könnte was an dem Baustein falsch ist.
Ich habe in dem folgenden Code zwei Zeilen hinzugefügt (fett markiert). Die erste fett markierte Zeile scheint gar nicht angesprochen zu werden. Es kommt weder eine Fehlermeldung, noch werden die permissions geändert. Wenn ich die zweite fett markierte Zeile einsetze bricht das Automator-Skript wie beschrieben ab.
Ich würde mich freuen, wenn mir hier jemand weiterhelfen kann!
ich nutze in einem AppleScript den Automator-Baustein "Upload to FTP" von Peter Dekkers. Da ich eine Wordpress-Galerie damit erzeugen möchte, müssen die hochgeladenen Ordner Schreibrechte mit dem Befehl chmod erhalten.
Leider hat Peter diese Option in seinem Baustein nicht berücksichtigt und auch keine Zeit sie einzubauen.
Teil dieses Bausteins ist ein Perl-Skript das die FTP-Kommandos ausführt. Das habe ich versucht zu erweitern. Leider bricht das Automator Script jetzt immer an dem FTP-Baustein ab, ohne eine Fehlermeldung auszugeben aus der man entnehmen könnte was an dem Baustein falsch ist.
Ich habe in dem folgenden Code zwei Zeilen hinzugefügt (fett markiert). Die erste fett markierte Zeile scheint gar nicht angesprochen zu werden. Es kommt weder eine Fehlermeldung, noch werden die permissions geändert. Wenn ich die zweite fett markierte Zeile einsetze bricht das Automator-Skript wie beschrieben ab.
Ich würde mich freuen, wenn mir hier jemand weiterhelfen kann!
Code:
#!/usr/bin/env perl
# main.command
# Upload to FTP
# v1.5
# Created by Peter Dekkers on 15/07/2005.
# Many thanks to Tom Davies for fixing a bug in the directory recursion.
# Many thanks to Marcel Rivard for fixing an issue with line endings at the end of filenames.
# Copyright 2005 Editkid. All rights reserved.
open STDERR, ">/dev/console";
# Grab values we care about from the UI
$ftp_server = $ENV{'ftp_server'};
$ftp_user = $ENV{'ftp_user'};
$ftp_pass = $ENV{'ftp_pass'};
$ftp_dir = $ENV{'ftp_dir'};
$ftp_protocol = $ENV{'ftp_protocol'} + 0;
$ftp_base_url = $ENV{'ftp_base_url'};
$ftp_port = $ENV{'ftp_port'} + 0;
$ftp_invisibles = $ENV{'ftp_invisibles'} + 0;
$ftp_proxy = $ENV{'ftp_proxy'};
$ftp_pasv = $ENV{'ftp_pasv'} + 0;
# check if the basic required options are filled in
if(!$ftp_server || $ftp_server eq ''){
myerr("Please supply an FTP server.");
}
# set the default alert time
if($ftp_alert_time < 0.1){
$ftp_alert_time = 5;
}
# check if the $ftp_base_url has a trailing slash, if not, add it
if($ftp_base_url){
my $fragment = substr $ftp_base_url, -1, 1;
if($fragment ne "/"){
$ftp_base_url=$ftp_base_url.'/';
}
}
# check if the $ftp_server starts with ftp://, and if so, remove it
if($ftp_server){
my $fragment2 = substr $ftp_server, 0, 6;
if($fragment2 eq "ftp://"){
# remove it
$ftp_server = substr $ftp_server, 6, (length($ftp_server)-6);
}
}
# create global clipboard contents variable
$global_clipboard='';
# Grab all the input
@files = <>;
$file_count = $#files + 1;
# error messaging
sub myerr {
my ($my_mess) = $_[0];
$message = "FTP Upload error:\n".$my_mess;
system "osascript -e 'tell application \"Finder\"' -e 'activate' -e 'display dialog \"$message\" buttons {\"OK\"} default button \"OK\" with icon 1' -e 'end tell'";
$ftp->quit;
die 'FTP Upload failed: '.$my_mess;
}
# Sub for recursively processing directory contents
sub dir_travel {
# get dir path from params
my ($my_dir) = $_[0];
my ($global_url_path) = $_[1];
# check for trailing slash
if($my_dir){
my $fragment3 = substr $my_dir, -1, 1;
if($fragment3 ne "/"){
$my_dir=$my_dir.'/';
}
}
# change local dir
chdir($my_dir);
# get dir name
my @dir_name = split(/\//, $my_dir);
$dir_name = $dir_name[$#$dir_name];
# set global path var for copying the URL
$global_url_path=$global_url_path.$dir_name.'/';
# chdir
if ($ftp_protocol == 0){
$ftp->cwd($dir_name) or myerr("Could not change to directory: $dir_name.");
} elsif ($ftp_protocol == 1) {
}
# read contents
my $success = opendir(dir_handle, $my_dir);
my @dirs = readdir(dir_handle);
# close directory
closedir(dir_handle);
foreach $f (@dirs){
next if ($f eq "." || $f eq "..");
# we have a file or a dir
my $my_path = $my_dir.$f;
if (-d $my_path){
# directory
if ($ftp_protocol == 0){
# make dir
$ftp->mkdir($f);
[B][COLOR="Blue"]$ftp->chmod(0777, $f);[/COLOR][/B]
} elsif ($ftp_protocol == 1) {
}
# recursive action
&dir_travel($my_path, $global_url_path);
} else {
# file
if ($ftp_protocol == 0){
# check if we need to upload invisible files
if($ftp_invisibles == 0){
# we can't upload invisibles, so check if this is one
$invisi_fragment = substr $f, 0, 1;
} else {
$invisi_fragment=' ';
}
# evaluate if this is an invisible file
if($invisi_fragment ne "."){
# put file
$ftp->put($f) or myerr("Could not upload file: $global_url_path$f.");
# add to uploaded files output
print $ftp_base_url.$global_url_path.$f."\n";
# add to clipboard variable
$global_clipboard=$global_clipboard.$ftp_base_url.$global_url_path.$f."\n";
}
} elsif ($ftp_protocol == 1) {
}
}
}
chdir("..");
$ftp->cwd("..") or myerr("Could not change to directory: ..");
}
if ($ftp_protocol == 0){
# set FTP port to 21 as default
if($ftp_port == 0){
$ftp_port = 21;
}
# init FTP connection
use Net::FTP;
if($ftp_proxy ne ''){
$ftp = Net::FTP->new($ftp_server,Port=>$ftp_port,Firewall=>$ftp_proxy,Passive=>$ftp_pasv) or myerr("Could not access $ftp_server at port $ftp_port using proxy $ftp_proxy.");
} else {
$ftp = Net::FTP->new($ftp_server,Port=>$ftp_port,Passive=>$ftp_pasv) or myerr("Could not access $ftp_server at port $ftp_port.");
}
# do log in
$ftp->login($ftp_user,$ftp_pass) or myerr("Your username and/or password are not accepted.");
# change to the right base dir
if($ftp_dir){
$ftp->cwd($ftp_dir) or myerr("Could not change to directory: $ftp_dir.");
}
# set binary mode transfers
$ftp->binary();
# loop input
for ( $i = 0; $i < $file_count; $i++ ) {
# MTR hack to get rid of line ending... (thanks Marcel Rivard!)
chomp($files[$i]);
# get last part of the path (dir or file)
@my_file_or_dir = split(/\//, $files[$i]);
$my_file_or_dir = $my_file_or_dir[$#$my_file_or_dir];
# check if we have a directory or a file
if (-d $files[$i]){
# create directory
$ftp->mkdir($my_file_or_dir);
[B][COLOR="blue"]$ftp->chmod(0777, $my_file_or_dir);[/COLOR][/B]
# fire function to recursively process this directory
dir_travel($files[$i],"");
} else {
# chdir to local directory
$my_filename_length = length($my_file_or_dir);
$my_fullpath_length = length($files[$i]);
$my_path_length = $my_fullpath_length - $my_filename_length;
$local_dir = substr $files[$i], 0, $my_path_length;
chdir($local_dir);
# hack to remove ' from the end...
chomp($my_file_or_dir);
# check if we need to upload invisible files
if($ftp_invisibles == 0){
# we can't upload invisibles, so check if this is one
$invisi_fragment = substr $my_file_or_dir, 0, 1;
} else {
$invisi_fragment = ' ';
}
# evaluate if this is an invisible file
if($invisi_fragment ne "."){
# put file
$ftp->put($my_file_or_dir) or myerr("Could not upload file: $ftp_base_url$my_file_or_dir.");
# add to uploaded files output
print $ftp_base_url.$my_file_or_dir."\n";
# add to clipboard variable
$global_clipboard=$global_clipboard.$ftp_base_url.$my_file_or_dir."\n";
}
}
}
# close FTP connection
$ftp->quit;
} elsif ($ftp_protocol == 1) {
print 'SFTP';
}
exit(0);