Automator: Building an FTP Workflow

Brandon.Bohling

Registered
I realize to the Automator pros this is dead simple, but for a newbie I am having a heck of a time. All I want to do is build a workflow that...

1) downloads (to my local system) two files from my FTP site
2) uploads those same two files to a different location on my FTP site

I've come close, but when the files are saved to my local system instead of being saved as sitemap.xml (as it should) it is being saved as: Sitemap\files\sitemap.xml, which is my FTP path. I suppose I could add the rename feature in the workflow, but I would think I should be able to save the files correctly. Or better yet, not even have to save to my local system.

Anyone help the challenged? ;)
 
Have you tried using Transmit as your FTP program? I believe it has some Automator actions available with/for it.
 
While there are FTP applications that have associated 'Automator' actions and / or AppleScript scripts - either by the applications' creator(s) or others ... there are also other ways to download and / or upload via FTP files - without any application(s).

Place the following code in to a 'Script Editor' window, or into an 'Automator's 'Automator' library 'Run AppleScript' action panel -

----- Code starts here.

set user_Name to "your_user_name" - User Name.
set pass_Word to "your_password" -- Password

set file01 to "file01.ext" -- File to download.
set file02 to "file02.ext" -- File to download.

set tDirectory to "upload_directory" -- Directory to upload to.

set bURL to "ftp_Server_Address" -- FTP server.

set tDate to do shell script ("date +%Y%m%d/")

try
do shell script ("mkdir $HOME/Desktop/" & tDate & "/")
end try

-- Download file01.
try
do shell script ("curl ftp://" & user_Name & ":" & pass_Word & "@" & bURL & "/" & file01 & " >> " & "$HOME/Desktop/" & tDate & "/" & file01)
end try

-- Download file02.
try
do shell script ("curl ftp://" & user_Name & ":" & pass_Word & "@" & bURL & "/" & file02 & " >> " & "$HOME/Desktop/" & tDate & "/" & file02)
end try

-- Upload file01.
try
do shell script ("curl -T $HOME/Desktop/" & tDate & "/" & file01 & " -u " & user_Name & ":" & pass_Word & " ftp://" & bURL & "/" & tDirectory & "/")
end try

-- Upload file02.
try
do shell script ("curl -T $HOME/Desktop/" & tDate & "/" & file02 & " -u " & user_Name & ":" & pass_Word & " ftp://" & bURL & "/" & tDirectory & "/")
end try

----- Code ends here.

... Or, instead - with 'Automator', create an 'Automator' library 'Run Shell Script' panel, and place the following code into it.

----- Code starts here.

#!/bin/bash

user_Name="your_user_name" # User Name.
pass_Word="your_password" # Password

file01="file01.ext" # File to download.
file02="file02.ext" # File to download.

tDirectory="upload_directory" # Directory to upload to.

bURL="ftp_Server_Address" # FTP server.

tDate=$(date +%Y%m%d)

mkdir $HOME/Desktop/$tDate/

# Download file01.
curl ftp://$user_Name:$pass_Word@$bURL/$file01 >> $HOME/Desktop/$tDate/$file01

# Download file02.
curl ftp://$user_Name:$pass_Word@$bURL/$file02 >> $HOME/Desktop/$tDate/$file02

# Upload file01.
curl -T $HOME/Desktop/$tDate/$file01 -u $user_Name:$pass_Word ftp://$bURL/$tDirectory/

# Upload file02.
curl -T $HOME/Desktop/$tDate/$file02 -u $user_Name:$pass_Word ftp://$bURL/$tDirectory/

----- Code ends here.

Basically, two files at the root level of the FTP server are downloaded into a created folder (of the current date) on the 'Desktop'. The downloaded files are then uploaded to the FTP server - into its 'upload_directory' directory.
 
Back
Top