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

10 posts in this topic

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]



Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites



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:"

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

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:



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?

Share this post

Link to post
Share on other sites


I am having trouble entering line 4 in the above script. The value of $script rejects the 'do shell script' as an unrecognised table.

How do we define the script in Filemaker 14

Am I missing something?

Edited by bmcintosh46

Share this post

Link to post
Share on other sites
On 11 February 2013 at 3:44 AM, uemtux said:

"do shell script "curl -T " & $path_unix & " ftp://USERNAME:PASSWORD@FTP_HOST/FTP_DIRECTORY/" & $file_name &"""

But I cannot get this text into the variable value field.

Edited by bmcintosh46

Share this post

Link to post
Share on other sites

I believe it needs to be:

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


Share this post

Link to post
Share on other sites

Thanks Comment

It took me a number of hours but I did eventually work this out. Seemed strange to me that other were excited about the script working and yet it wasn't displayed correctly.

Thanks for you time

Share this post

Link to post
Share on other sites
2 minutes ago, bmcintosh46 said:

Seemed strange to me that other were excited about the script working and yet it wasn't displayed correctly.

It probably was displayed correctly back in 2013, but didn't survive all the forum up?grades since.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By fm8443
      I have a simple Applescript that works in Script Editor
      tell application "Keyboard Maestro Engine" 
      do script "Search the Web" 
      end tell
      I add this same script (with escape chars) to my RESOURCES::A_SCRIPT field inside FM.
      The RESOURCES table is not connected to the other tables in the graph.
      "tell application \"Keyboard Maestro Engine\" 
      do script \"Search the Web\" 
      end tell"
      I've tried this with this field being defined as a Global Storage Field or not.  Similar problems with both.
      I have an FM Script called EXECUTE:
      Perform Applescript (RESOURCES::A_SCRIPT)
      When I run this FM Script I get an error message:
      "Error: -2741" / "Expected EOL but found Command Name"
      I've have tried rebooting my Mac.
      Any ideas?
    • By sal88
      Hi all
      Fairly trivial (but annoying) problem here!
      I've just transferred all Invoice PDFs to their respective container fields - which is externally stored (non secure) on the FMS Server.
      However the first PDF in the table had an '_1' at the end of the filename on the server. When I cleared the field and re-added the PDF it then has '_2' at the end, and so on.
      The underscore disappeared when I transferred the container from 'Invoices/' to 'Invoices2/' but the problem remains when I transfer back to 'Invoices/'.
      It doesn't happen to any other PDFs/records, just this first one in the table. Any ideas how I can 'reset' this?
    • By Franco Pagano
      fmp 14 last release.
      i put this applescript in a global field  and also all the fmp field are global.
      i don't understand  wy it doesn't work, if the applescript var are set as ... "set ServerDisk to "afp://" ... it work.
      Were i am wrong?
      Many thanks.

          set ServerDisk to field ("ServerDisk_as" as text) of table ("__AS" as text)
          set ServerFolder to field ("ServerFolder_as" as text) of table ("__AS" as text)
          set VarAccount to field ("VarAccount" as text) of table ("__AS" as text)
          set VarPw to field ("VarPassWord" as text) of table ("__AS" as text)
      tell application "Finder"
          display dialog ServerFolder
          if not (disk ServerDisk exists) then
              mount volume ServerFolder as text as user name VarAccount with password VarPw
          end if
      end tell
    • By jbante
      I'm working on a function to extract text from a .txt.gz file in a container field:
      //SM_TextFromGZIP ( containerFieldName ) import java.util.zip.GZIPInputStream; import java.util.io.*; GZIPInputStream gunzip = new GZIPInputStream(fmpro.getContainerStream(containerFieldName)); InputStreamReader reader = new InputStreamReader(gunzip); BufferedReader pr = new BufferedReader(reader); String line; String finalOutput = \"\"; while ((line = pr.readLine()) != null)     finalOutput += line; return finalOutput; When I run this, I get this from the SMLastStackTrace function:
      java.io.IOException: com.prosc.fmkit.types.FMBinary$FMContainerInputStream.read() returned value out of range -1..255: -117     at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:250)     at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:237)     at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:140)     at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:56)     at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:65)     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)     ... Any thoughts on a fix or alternative solution?
    • By naio
      My old fp7 solution had some fields that store the path to external pdf files, the files were stored in the same server machine and the path were like "file://oldserver/folder/file", the pdf files are shown in the solution through a webviewer field. The solution is developed under the 'separation model'.
      I just converted the solution to FM15 and I moved into a new server, at present I have both servers up and running, so the fmp12 database with fields pointing to "file://oldserver/folder/file" still shows pdf files as expected.
      Given that I want the paths to point to a certain folder into the new server I'm trying to find the right path to the new location of files but so far I haven't been able even thought I made sure that users fmserver and fmsadmin have full permissions on the folder that stores the pdf files.
      On the other hand I've seen that FMS15 creates a folder named "RC_Data_FMS" with a subfolder for each fmp12 file where the external container data is meant to be stored. Am I forced to store my pdf files in there OR somewhere else in the network?
      Thank you in advance.