uemtux

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]

 

Enjoy!

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

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

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:

http://help.filemaker.com/app/answers/detail/a_id/11888/~/container-field-enhancements-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?

Share this post


Link to post
Share on other sites

Hi 

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 & "\""

Untested.

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

    • Container export to IOS Photo app?
      By 34South
      I have developed a solution for IOS devices which also utilizes scripts that facilitate importing of GPS coordinates and especially photos from the device, i.e. iPhone or iPad, within FMGo. Although I have scripted the possibility of emailing images originally captured by the solution outside of the solution, there does not seem to be a possibility for exporting the captured image to the Photos app and thus pushing them to the iCloud. I know one could first capture the image in the Camera app and then import it into a container within the solution, but this distracts from the all-in-one nature of my solution, where quick image capture is paramount. Ideally, the user would use the solution to capture the image and related contextual data, but also elect to save such an image in the Photo app at a later stage to permit sharing it to social media apps, for example.
       I'm fairly advanced, having used FM since the Claris days.
    • PDF on FileMaker Server 14 (Windows) generating security error
      By typewriter
      I am experiencing a nasty problem with a Filemaker Server 14.0.4.412 on Windows Server 2012R2. PDF s in a container field don't display, but instead either one of two things happen:
      1 on FMPA14 running on Terminal Server (Windows), an error displays 'Security settings do not allow downloading this file' (or something similar, the message is in Dutch). the dialog doesn't display a FileMaker icon, only a yellow warning sign (Windows?). The Terminal server has Acrobat Reader DC installed, which can open the PDF locally. Opening the FMP database with the FMPA locally displays the PDF, both stroed 'in file' and as Remote Container.
      2 on FMP14 running on a normal Windows workstation, the PDF is opened in Adobe Acrobat in a separate window instead of being displayed in the container field.
      We checked ports 80, 443, 16000 and 16001 being blocked on the Firewall (clients and server are within the same LAN). PNG and JPG will display OK, and the PDFs are stored properly, so it seems.
      Where is this security error coming from? 
      Could it be a problem with Windows Server 2012 not allowing Tomcat Server to run? And if so, what can I do to fix this?
    • Signature in FilemakerPro 14
      By muskee
      Hi everyone!
      I'm currently using filemaker pro advanced 14, and I'm making some layouts for the Ipad platform. Is there a way to set up a container field to capture signatures via this method? how?
    • Insert PDF is greyed out on my container field
      By Brad Mathews
      The Insert PDF context menu item is greyed out on my container field when I have my database open locally. My Google Fu has failed me on solving this.
      My container field is on a layout, not in a portal. I have Interactive Content checked. I have a PDF viewer working in IE. (Zeon - I do not know where I got this plugin - I very rarely use IE.). I also have an older version of NitroPDF Pro which I use daily, but no IE plugin at the moment. The container field Storage settings are "Store container data externally" and using Open storage option. I also tried the secure storage option which was the default. I have FM Pro 14.0.4 and this database is not converted from earlier version. I am using Windows 10 I can drag and drop a PDF into the container and I get the PDF icon, but it is not interactive However it is interactive (both native and WebDirect) when I upload the database to FM Server - which is also my local computer for now.  But in all cases Insert PDF is greyed out. The only other solution that the web has coughed up it to use the newest version of Adobe Acrobat Reader which is not an option - I refuse to use that piece of #$@&.
      What else can I try?
      Thanks, Brad
    • Minimalist Serverside FTP Upload?
      By wonfuji
      Hi
      <REDACTED>  User was suffering from Friday as well as brain meltdown and general stupidity.
      Stephen