Jump to content

  •  

Photo

Upload Contents of Container Field to FTP (Mac OS / AppleScript technique)

applescript container macos ftp curl

  • Please log in to reply
4 replies to this topic

#1 uemtux  Professional FM Guy for 5 Years

uemtux
  • Members
  • 75 posts
  • FM Application:12 Advance
  • Platform:Mac OS X Snow Leopard
  • Skill Level:Intermediate
  • Time Online: 1d 8h 30m 29s

Posted 11 February 2013 - 08:44 AM

Hi All, 

 

I just thought I'd try to give back to the community that has given so much to me by writing a little tutorial. This technique is one I developed on Macs. Mac OS X has the curl command line tool as part of the default installation. Curl is like a web swiss army knife. You can fetch files, POST data, upload to or download from FTP servers etc... so it brings a lot of functionality to the table which isn't built into FileMaker. I make use of curl through the "do shell script" AppleScript command, which in FileMaker I use through the "Perform AppleScript" script step. Here's a simple 6 line script that lets you take the contents of a container field and upload it to an FTP site. Substitute your container field in the first and fifth lines and your FTP information in the $script variable to make it functional. This script could be extended by actually having variables for the FTP credentials/location too but I've kept it simple here just to demonstrate the technique.

 

 

set variable [$file_name; GetAsText(YourTable::YourContainerField)]

set variable [$path_temp; Get(TemporaryPath) & $file_name]

set variable [$path_unix; Middle($path_temp ; Position($path_temp ; "/" ; 1 ; 2) ; Length($path_temp))]

set variable [$script; "do shell script \"curl -T " & $path_unix & " ftp://USERNAME:PASSWORD@FTP_HOST/FTP_DIRECTORY/" & $file_name &"\""]

Export Field Contents [YourTable::YourContainerField; "$path_temp"]

Perform AppleScript [$script]

 

Enjoy!


  • 0
Martin Brice - my old and good friend who promised me we would not get in trouble and who, I might add, did not.

#2 RobinDC  newbie

RobinDC
  • Members
  • 9 posts
  • FM Application:12 Advance
  • Platform:Mac OS X Lion
  • Skill Level:Expert
  • Certification:12
  • Membership:TechNet
  • Time Online: 1h 53m 31s

Posted 14 March 2013 - 07:12 PM

This is fantastic, and so simple. It worked for me on the first try. I couldn't believe it. Thank you.


  • 0

#3 uemtux  Professional FM Guy for 5 Years

uemtux
  • Members
  • 75 posts
  • FM Application:12 Advance
  • Platform:Mac OS X Snow Leopard
  • Skill Level:Intermediate
  • Time Online: 1d 8h 30m 29s

Posted 20 November 2013 - 09:15 AM

NOTE FOR FUTURE VIEWERS OF THIS THREAD:

 

The script as-is may not work since as of FileMaker 12 GetAsText(containerField) returns more than just the filename. You may have to look for and remove additional text such as "remote:"


  • 0
Martin Brice - my old and good friend who promised me we would not get in trouble and who, I might add, did not.

#4 RodM  journeyman

RodM
  • Members
  • 420 posts
  • LocationEugene OR
  • FM Application:12 Advance
  • Platform:Windows 7
  • Skill Level:Intermediate
  • Time Online: 3d 13h 13m 23s

Posted 20 November 2013 - 09:32 AM

Wondering...Is there a Apple script replacement for Windows?


  • 0
RodM

#5 johnmaclulich  newbie

johnmaclulich
  • Members
  • 6 posts
  • FM Application:10 Advance
  • Time Online: 17s

Posted 22 February 2014 - 06:14 PM

Simple - and did just what it is supposed to do!

 

FMPro 13 allows easier extraction of the container file name, by using the GetContainerAttribute function:

GetContainerAttribute ( GetContainerAttribute ( sourceField ; attributeName ) and substituting "filename" for "attributeName".

Other attributes can easily be read, too, as listed here:

http://help.filemake...ts-in-filemaker

 

HOWEVER... I suspect that the "curl-T" command has problems with specific characters in the file name.

I have found that the script just hangs if the file name contains spaces, "&", or other such non-UNIX-friendly characters.

Is there a way to overcome this, and still preserve the original filename?


  • 0
John MacLulich
Owner & Filemaker in-house developer
Pure Colours Digital Imaging
Sydney, Australia





FMForum Advertisers