CopyFile[file1,file2]
copies from the local, remote or cloud file file1 to the local, remote or cloud file file2.
CopyFile
CopyFile[file1,file2]
copies from the local, remote or cloud file file1 to the local, remote or cloud file file2.
Details and Options
- CopyFile takes file specifications in the following forms:
-
"path" local file given by the specified relative or absolute path File["path"] local file specified by path RemoteFile[url] remote file specified by url URL["url"] web or other URL LocalObject[…] persistent local object CloudObject[…] cloud object ExternalStorageObject[…] external storage object (e.g. IPFS, Dropbox) - In CopyFile[src,dest] the source src can be specified by a URL with any of the following schemes:
-
http: HTTP protocol https: secure HTTP protocol ftp: file transfer protocol sftp: secure file transfer protocol scp: secure copy protocol file: local file - The destination dest can be specified by a URL with any of the following schemes:
-
sftp: remote file accessible through the SFTP protocol scp: remote file accessible through the SCP protocol file: local file - RemoteFile["url",Authentication->auth] can be used to specify authentication information for the secure file transfer and copy protocols.
- CopyFile sets the modification date for file2 to be the same as for file1.
- CopyFile returns the full name of the file it copies to and $Failed if it cannot copy.
- When copying to a cloud object, CopyFile returns that CloudObject expression.
- Cloud objects created by CopyFile are assigned the permissions specified by $Permissions.
- CopyFile has the following option:
-
OverwriteTarget False whether to overwrite if the target file already exists
Examples
open all close allBasic Examples (1)
file = FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData", "coneflower.jpg"}]CopyFile[file, FileNameJoin[{$TemporaryDirectory, "coneflower.jpg"}]]Import[%]DeleteFile[FileNameJoin[{$TemporaryDirectory, "coneflower.jpg"}]];Scope (7)
Copy a file from the local file system to the Wolfram Cloud:
file = FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData", "coneflower.jpg"}];CopyFile[file, CloudObject["flower2"]]Copy a cloud object to another location within the Wolfram Cloud:
CopyFile[CloudObject["flower2"], CloudObject["flower3"]]Copy a cloud object to the local file system:
CopyFile[CloudObject["flower2"], "flower.jpg"]"/Users/wolfram/Desktop/flower.jpg"Copy a file specified as a File object:
file = FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData", "coneflower.jpg"}]
cfile = FileNameJoin[{$TemporaryDirectory, "coneflower2.jpg"}];CopyFile[File[file], File[cfile]]DeleteFile[File[cfile]]CopyFile can copy among local files, local objects, and cloud objects:
file = FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData", "coneflower.jpg"}];CopyFile[file, LocalObject["flower"]]LocalObject["file:///Users/wolfram/Library/Wolfram/Objects/flower"]CopyFile[LocalObject["flower"], CloudObject["flower1"]]Import[%]The source can be any form of web URL:
CopyFile[URL["https://wolfram.com/"], FileNameJoin[{$TemporaryDirectory, "homepage.html"}]]Copy a file to a remote machine using the scp secure protocol:
CopyFile["/tmp/test.m", URL["sftp://host.example.com/tmp/test.m"]]Copy a file from a remote machine using the scp secure protocol:
CopyFile[URL["scp://host.example.com/tmp/test.m"], "/tmp/test.m"]Copy a file to a remote machine using the sftp secure protocol:
CopyFile["/tmp/test.m", URL["sftp://host.example.com/tmp/test.m"]]Copy a file from a remote machine using the sftp secure protocol:
CopyFile[URL["sftp://host.example.com/tmp/test.m"], "/tmp/test.m"]Copy a file from a remote machine using a different user:
CopyFile[URL["sftp://user@host.example.com/tmp/test.m"], "/tmp/test.m"]Copy from an ExternalStorageObject to a local file:
CopyFile[ExternalStorageObject["Qmd1HkTU55zaCDnX2wbnVoq15aPHdutn8c3epuJFAt4dgf",
Association["ExternalStorageBase" -> "IPFS", "FileHash" -> "38cb6f3cd68c6c723591a8a385732560"]], "~/Downloads/Wolfram/Spikey.png"]Import[%]Copy from an ExternalStorageObject to a cloud object:
CopyFile[ExternalStorageObject["Qmd1HkTU55zaCDnX2wbnVoq15aPHdutn8c3epuJFAt4dgf",
Association["ExternalStorageBase" -> "IPFS", "FileHash" -> "38cb6f3cd68c6c723591a8a385732560"]], CloudObject["Spikey.png"]]Import[%]Possible Issues (1)
Copying to the cloud requires the CloudObject wrapper:
CopyFile[URL["https://www.wolfram.com"], "https://www.wolframcloud.com/obj/documentation/tmp/website"]CopyFile[URL["https://www.wolfram.com"], CloudObject["https://www.wolframcloud.com/obj/documentation/tmp/website"]]See Also
RenameFile DeleteFile CopyDirectory CreateFile URLDownload ExternalStorageObject
Function Repository: BackupFile
Tech Notes
Related Guides
History
Introduced in 1991 (2.0) | Updated in 2020 (12.1)
Text
Wolfram Research (1991), CopyFile, Wolfram Language function, https://reference.wolfram.com/language/ref/CopyFile.html (updated 2020).
CMS
Wolfram Language. 1991. "CopyFile." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/CopyFile.html.
APA
Wolfram Language. (1991). CopyFile. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CopyFile.html
BibTeX
@misc{reference.wolfram_2026_copyfile, author="Wolfram Research", title="{CopyFile}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/CopyFile.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_copyfile, organization={Wolfram Research}, title={CopyFile}, year={2020}, url={https://reference.wolfram.com/language/ref/CopyFile.html}, note=[Accessed: 12-June-2026]}