Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
CURL.CreateOutputFile
Creates output file for downloading data.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
CURL | 2.6 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example |
---|---|---|
curl | The CURL session handle. | $curl |
Path | Native file path. | C:\Documents\Test.Txt |
Result
Returns "OK" on success or error message.
Description
Creates output file for downloading data.If you set MBS( "CURL.SetOptionFileOnlyMode"; $curl; 1 ), the data is only written to file and not available with CURL.GetResult* functions. If creation of the file fails, you get an error message back, but still your transfer will probably succeed.
Do not call this method while a transfer is running.
Sets CURL.SetOptionFileOnlyMode to 1 for version 9.3 or later automatically.
Please call CURL.CloseOutputFile later to make sure the file is closed before you process the file.
This function requires a native path. Use Path.FileMakerPathToNativePath to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use FileDialog functions.
For Server be aware that server has limited permissions and may not be able to access all files on a computer.
Examples
Write data to a file on Mac in temp folder:
MBS( "CURL.CreateOutputFile"; $curl; "/tmp/download.dat" )
Write data only to file on Windows:
MBS( "CURL.SetOptionFileOnlyMode"; $curl; 1 )
MBS( "CURL.CreateOutputFile"; $curl; "c:\download.dat" )
Download URL to temp file:
Set Variable [$curl; Value:MBS("CURL.New")]
#this is URL to download
Set Variable [$url; Value:"https://www.monkeybreadsoftware.com/filemaker/test.txt"]
#get file name from URL
Set Variable [$name; Value:MBS( "Path.LastPathComponent"; $URL )]
#now make temp file path
Set Variable [$path; Value:MBS( "Path.AddPathComponent"; MBS( "Folders.SystemTemporary" ); $name )]
#set URL to download
Set Variable [$r; Value:MBS("CURL.SetOptionURL"; $curl; $url)]
#open destination file
Set Variable [$r; Value:MBS("CURL.CreateOutputFile"; $curl; $path)]
#run transfer
Set Field [CURL Test::Result; MBS("CURL.Perform"; $curl)]
#close destination file
Set Variable [$r; Value:MBS("CURL.CloseOutputFile"; $curl)]
#get debug messages
Set Field [CURL Test::debug; MBS("CURL.GetDebugMessages"; $curl)]
Set Variable [$result; Value:MBS("CURL.Release"; $curl)]
Download file via SFTP to file on disk:
Set Variable [$curl; Value:MBS("CURL.New") ]
# set download URL, e.g. sftp://monkeybreadsoftware.net/test.jpg
Set Variable [$result; Value:MBS("CURL.SetOptionURL"; $curl; SFTP Download::URL )]
# build file path on disk and open output file
Set Variable [$name; Value:GetValue(SFTP Download::FileName; 1)]
Set Variable [$path; Value:MBS( "Path.AddPathComponent"; SFTP Download::FolderPath; $name )]
Set Variable [$r; Value:MBS("CURL.CreateOutputFile"; $curl; $path)]
# login only via password
Set Variable [$result; Value:MBS( "CURL.SetOptionSSHAuthTypes"; $curl; 2+8 )]
# set credentials
Set Variable [$result; Value:MBS("CURL.SetOptionUserName"; $curl; SFTP Download::UserName )]
Set Variable [$result; Value:MBS("CURL.SetOptionPassword"; $curl; SFTP Download::Password )]
# run transfer
Set Field [SFTP Download::ErrorCode; MBS("CURL.Perform"; $curl)]
# check debug log for errors
Set Field [SFTP Download::Debug; MBS("CURL.GetDebugMessages"; $curl)]
# free CURL session
Set Variable [$result; Value:MBS("CURL.Release"; $curl)]
Batch download a lot of files via FTP/SFTP:
# URL field contains ftp or sftp URL with / on end.
# FileList field contains list of files to load
# OutputPath field contains folder path on disk
#
Set Variable [$i; Value:1]
Set Variable [$max; Value:ValueCount ( SFTP Download::FileList )]
#
Set Variable [$curl; Value:MBS("CURL.New")]
#
# login only via password
Set Variable [$result; Value:MBS( "CURL.SetOptionSSHAuthTypes"; $curl; 2+8 )]
#
# set credentials
Set Variable [$result; Value:MBS("CURL.SetOptionUserName"; $curl; SFTP Download::UserName )]
Set Variable [$result; Value:MBS("CURL.SetOptionPassword"; $curl; SFTP Download::Password )]
#
# start loop over file lists
Loop
#
Set Variable [$name; Value:GetValue ( SFTP Download::FileList ; $i )]
#
# build file path on disk and open output file
Set Variable [$path; Value:MBS( "Path.AddPathComponent"; SFTP Download::OutputPath; $name )]
Set Variable [$r; Value:MBS("CURL.CreateOutputFile"; $curl; $path)]
#
# set URL with file name
Set Variable [$result; Value:MBS("CURL.SetOptionURL"; $curl; SFTP Download::URL & $name )]
#
# run transfer
Set Field [SFTP Download::ERGEBNIS; MBS("CURL.Perform"; $curl)]
#
# query debug log
Set Field [SFTP Download::DEBUG; MBS("CURL.GetDebugMessages"; $curl)]
#
Set Variable [$i; Value:$i +1]
Exit Loop If [$max = $i]
#
End Loop
Set Variable [$result; Value:MBS("CURL.Release"; $curl)]
See also
- CURL.CloseOutputFile
- CURL.CreateHeaderOutputFile
- CURL.Perform
- CURL.Release
- CURL.SetOptionSSHAuthTypes
- CURL.SetOptionURL
- CURL.SetOptionUserName
- Folders.System
- Folders.SystemTemporary
- Path.AddPathComponent
Release notes
- Version 9.3
- Changed CURL to not collect data in memory if used with CURL.CreateOutputFile.
Example Databases
- CURL/CURL Download on Server
- CURL/CURL Download Picture
- CURL/CURL Download Text
- CURL/FTP/CURL FTP Download all Files in Directory
- CURL/FTP/CURL FTP Download File
- CURL/FTP/CURL FTP Upload File
- CURL/SFTP/CURL sFTP Upload File
Blog Entries
- MBS FileMaker Plugin, version 9.3pr5
- Comparing Base Elements Plugin to MBS FileMaker Plugin
- MBS Filemaker Plugin, version 2.6pr4
This function checks for a license.
Created 18th August 2014, last changed 3th January 2023