CURL.CreateOutputFile
---------------------

Creates output file for downloading data.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [CURL](component_CURL.md) | [2.6](newinversion26.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "CURL.CreateOutputFile"; curl; Path ) 

**MBS**( **"CURL.CreateOutputFile";** /\* Creates output file for downloading data. \*/  
**$curl**; /\* The CURL session handle. \*/   
**$Path**) /\* Native file path.e.g. C:\\Documents\\Test.Txt \*/ 

### 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](CURLSetOptionFileOnlyMode.md)"; $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](CURLSetOptionFileOnlyMode.md) to 1 for version 9.3 or later automatically.  
Please call [CURL.CloseOutputFile](CURLCloseOutputFile.md) later to make sure the file is closed before you process the file.  
  
This function requires a native path. Use [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md) 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](component_FileDialog.md) 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](CURLSetOptionFileOnlyMode.md)"; $curl ; 1 )  
MBS ( "CURL.CreateOutputFile"; $curl ; "c:\\download.dat" )  
Download URL to temp file:

 Set Variable \[$curl ; Value:MBS ("[CURL.New](CURLNew.md)")\]  
\#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](PathLastPathComponent.md)"; $URL )\]  
\#now make temp file path   
Set Variable \[$path ; Value:MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; MBS ( "[Folders.SystemTemporary](FoldersSystemTemporary.md)" ); $name )\]  
\#set URL to download   
Set Variable \[$r ; Value:MBS ("[CURL.SetOptionURL](CURLSetOptionURL.md)"; $curl ; $url )\]  
\#open destination file   
Set Variable \[$r ; Value:MBS ("CURL.CreateOutputFile"; $curl ; $path )\]  
\#run transfer   
Set Field \[CURL Test::Result ; MBS ("[CURL.Perform](CURLPerform.md)"; $curl )\]  
\#close destination file   
Set Variable \[$r ; Value:MBS ("[CURL.CloseOutputFile](CURLCloseOutputFile.md)"; $curl )\]  
\#get debug messages   
Set Field \[CURL Test::debug ; MBS ("[CURL.GetDebugMessages](CURLGetDebugMessages.md)"; $curl )\]  
Set Variable \[$result ; Value:MBS ("[CURL.Release](CURLRelease.md)"; $curl )\]  
Download file via SFTP to file on disk:

 Set Variable \[$curl ; Value:MBS ("[CURL.New](CURLNew.md)") \]  
\# set download URL, e.g. sftp://monkeybreadsoftware.net/test.jpg   
Set Variable \[$result ; Value:MBS ("[CURL.SetOptionURL](CURLSetOptionURL.md)"; $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](PathAddPathComponent.md)"; SFTP Download::FolderPath ; $name )\]  
Set Variable \[$r ; Value:MBS ("CURL.CreateOutputFile"; $curl ; $path )\]  
\# login only via password   
Set Variable \[$result ; Value:MBS ( "[CURL.SetOptionSSHAuthTypes](CURLSetOptionSSHAuthTypes.md)"; $curl ; 2+8 )\]  
\# set credentials   
Set Variable \[$result ; Value:MBS ("[CURL.SetOptionUserName](CURLSetOptionUserName.md)"; $curl ; SFTP Download::UserName )\]  
Set Variable \[$result ; Value:MBS ("[CURL.SetOptionPassword](CURLSetOptionPassword.md)"; $curl ; SFTP Download::Password )\]  
\# run transfer   
Set Field \[SFTP Download::ErrorCode ; MBS ("[CURL.Perform](CURLPerform.md)"; $curl )\]  
\# check debug log for errors   
Set Field \[SFTP Download::Debug ; MBS ("[CURL.GetDebugMessages](CURLGetDebugMessages.md)"; $curl )\]  
\# free CURL session   
Set Variable \[$result ; Value:MBS ("[CURL.Release](CURLRelease.md)"; $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](CURLNew.md)")\]  
\#   
\# login only via password   
Set Variable \[$result ; Value:MBS ( "[CURL.SetOptionSSHAuthTypes](CURLSetOptionSSHAuthTypes.md)"; $curl ; 2+8 )\]  
\#   
\# set credentials   
Set Variable \[$result ; Value:MBS ("[CURL.SetOptionUserName](CURLSetOptionUserName.md)"; $curl ; SFTP Download::UserName )\]  
Set Variable \[$result ; Value:MBS ("[CURL.SetOptionPassword](CURLSetOptionPassword.md)"; $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](PathAddPathComponent.md)"; 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](CURLSetOptionURL.md)"; $curl ; SFTP Download::URL &amp; $name )\]  
 #  
 # run transfer  
 Set Field \[SFTP Download::ERGEBNIS ; MBS ("[CURL.Perform](CURLPerform.md)"; $curl )\]  
 #  
 # query debug log  
 Set Field \[SFTP Download::DEBUG ; MBS ("[CURL.GetDebugMessages](CURLGetDebugMessages.md)"; $curl )\]  
 #  
 Set Variable \[$i ; Value:$i +1\]  
 Exit Loop If \[$max = $i \]  
 #  
End Loop  
Set Variable \[$result ; Value:MBS ("[CURL.Release](CURLRelease.md)"; $curl )\]  
### See also

- [CURL.CloseOutputFile](CURLCloseOutputFile.md)
- [CURL.CreateHeaderOutputFile](CURLCreateHeaderOutputFile.md)
- [CURL.Perform](CURLPerform.md)
- [CURL.Release](CURLRelease.md)
- [CURL.SetOptionSSHAuthTypes](CURLSetOptionSSHAuthTypes.md)
- [CURL.SetOptionURL](CURLSetOptionURL.md)
- [CURL.SetOptionUserName](CURLSetOptionUserName.md)
- [Folders.System](FoldersSystem.md)
- [Folders.SystemTemporary](FoldersSystemTemporary.md)
- [Path.AddPathComponent](PathAddPathComponent.md)

### Release notes

- **Version 9.3**
    - Changed CURL to not collect data in memory if used with [CURL.CreateOutputFile](http://www.mbsplugins.eu/CURLCreateOutputFile.shtml).

### Example Databases

- [CURL/CURL Download on Server](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/CURL%20Download%20on%20Server.shtml#1ScriptAnchor_)
- [CURL/CURL Download Picture](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/CURL%20Download%20Picture.shtml#3ScriptAnchor_)
- [CURL/CURL Download Text](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/CURL%20Download%20Text.shtml#3ScriptAnchor_)
- [CURL/FTP/CURL FTP Download all Files in Directory](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/FTP/CURL%20FTP%20Download%20all%20Files%20in%20Directory.shtml#5ScriptAnchor_)
- [CURL/FTP/CURL FTP Download File](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/FTP/CURL%20FTP%20Download%20File.shtml#2ScriptAnchor_)
- [CURL/FTP/CURL FTP Upload File](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/FTP/CURL%20FTP%20Upload%20File.shtml#2ScriptAnchor_)
- [CURL/SFTP/CURL sFTP Upload File](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/SFTP/CURL%20sFTP%20Upload%20File.shtml#7ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 9.3pr5](https://www.mbsplugins.de/archive/2019-07-13/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)
- [Comparing Base Elements Plugin to MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2017-10-24/Comparing_Base_Elements_Plugin/monkeybreadsoftware_blog_filemaker)
- [MBS Filemaker Plugin, version 2.6pr4](https://www.mbsplugins.de/archive/2012-02-17/MBS_Filemaker_Plugin_version_2/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 18th August 2014 , last changed 3th January 2023

  
[CURL.CreateHeaderOutputFile](CURLCreateHeaderOutputFile.md) - [CURL.ErrorCode](CURLErrorCode.md)

[HTML Version](CURLCreateOutputFile.shtml)