« Evaluate vs. Script T… | Home | MBS FileMaker Plugin,… »

Tip of the day: FTP File Upload

Sometimes you need to upload a file to FTP/FTPS/SFTP server, e.g. upload a backup. The following script does that and can run even on a FileMaker server:

Set Variable [$curl; Value:MBS("CURL.New")]

# Path to the input file with data to upload

Set Variable [$result; Value:MBS("CURL.OpenInputFile"; $curl; "/Users/cs/Desktop/test.jpg")]

# Set upload options

Set Variable [$result; Value:MBS("CURL.SetOptionURL"; $curl; "ftp://monkeybreadsoftware.de/test/test.jpg")]

Set Variable [$result; Value:MBS("CURL.SetOptionUpload"; $curl; 1)]

Set Variable [$result; Value:MBS("CURL.SetOptionPassword"; $curl; "secret")]

Set Variable [$result; Value:MBS("CURL.SetOptionUsername"; $curl; "account")]

# Run Transfer

Set Field [CURL Test::Result; MBS("CURL.Perform"; $curl)]

# get log

Set Field [CURL Test::DebugMessages; MBS("CURL.GetDebugAsText"; $curl)]

# and clean up

Set Variable [$result; Value:MBS("CURL.Cleanup"; $curl)]

As you see we pass in an URL for the ftp upload. Depending on whether we use ftp:// (unsecure), ftps:// (ftp with SSL) or sftp:// (ssh), we get the protocol for the URL. If you need to upload a container, you can use CURL.SetInputFile or for text the function CURL.SetInputText. Don't forget to include in the URL the new file name on the target. 

Other interesting options here are CURL.SetOptionFTPCreateMissingDirs for creating missing directories, CURL.SetOptionConnectionTimeout for setting connection timeout and CURL.SetOptionPort if your server doesn't use the standard port for the protocol.

The MBS Plugin supports SFTP, FTP and FTPS and you select it with URL prefix in your URL:

ftp://   is unencrypted ftp
ftps://   is encrypted ftp
sftp://   is file transfer via ssh

Claris FileMaker Plugin
06 03 16 - 12:28