Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 10.5   11.0   11.1   11.2   11.3   11.4   11.5   12.0   12.1   12.2    Statistic    FMM    Blog  

CURL.CreateOutputFile

Creates output file for downloading data.

Component Version macOS Windows Linux Server iOS SDK License
CURL 2.6 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes Free
MBS( "CURL.CreateOutputFile"; curl; Path )   More

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.GetDebugAsText"; $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.GetDebugAsText"; $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.GetDebugAsText"; $curl)]
    #
    Set Variable [$i; Value:$i +1]
    Exit Loop If [$max = $i]
    #
End Loop
Set Variable [$result; Value:MBS("CURL.Release"; $curl)]

See also

Release notes

Example Databases

Blog Entries

Created 18th August 2014, last changed 21st February 2022


CURL.CreateHeaderOutputFile - CURL.ErrorCode

Feedback: Report problem or ask question.


Start Chat