Files

The File and Folder resources allow you to operate on files and folders. While the two resources are similar, they are not exactly the same, so pay close attention to the documentation to ensure that you are operating on the correct resource for the operation you are trying to perform.

Download File

SDK Method

Files::File.download_file()

Return Object

nil

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
path
string
Required
Path to operate on.
local_path
string
Local destination path, including the file name. If omitted, the file is saved in the current working directory using the last component of path. An existing file at the local destination is overwritten.

Local paths follow your operating system's file naming rules. On Windows, trailing periods or spaces can be removed, so remote files whose names differ only by those characters can overwrite the same local file. To keep the downloads separate, pass local_path with distinct names that are valid on Windows.

On Windows, omitting local_path for a remote file name containing : raises InvalidParameterError. Pass local_path with a Windows-compatible file name to download the file.

Example Request

begin
  # Save as report.csv in the current working directory.
  Files::File.download_file("incoming/report.csv")
  
  # Choose a file name in an existing local directory.
  Files::File.download_file("incoming/report.csv", "downloads/vendor-report.csv")
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Upload File

SDK Method

Files::File.upload_file()

Return Object

File

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
path
string
Required
Path to operate on.
destination
string
Remote path to upload the file to.
params
object
Upload request parameters.
progress
callable
Called after each part of the upload is acknowledged, with a hash of total_bytes (the local file's size), acknowledged_bytes, part_number and part_bytes. Anything it raises is raised from upload_file and stops the upload: no later part is sent, and the upload is not completed.

Parameters

ParameterDescription
mkdir_parents
boolean
Create parent directories if they do not exist?

Example Request

begin
  file = Files::File.upload_file(
    path,
    destination,
    params: { mkdir_parents: true }
  )
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Open File

SDK Method

Files::File.open()

Return Object

File

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
path
string
Required
Path to operate on.
mode
string
Mode to open the file in.

Writing an IO, or any object that responds to read, eof? and close, uploads what it reads when the file is closed. Each part of the upload is filled from as many reads as it takes, so a source that returns fewer bytes than asked still sends full parts. A source that returns nothing while eof? is false raises Files::InvalidParameterError before that part is sent. Closing the file closes the source once the upload has been completed; if the upload or its completion fails, the source is left open. (Files::File.upload_chunks, which uploads from a source directly, needs only read and eof?, and does not close it.)

Example Request

begin
  File.open("local.txt") do |local_file|
    mode = "w"
    Files::File.open(path, mode) do |remote_file|
      remote_file.write(local_file.read)
    end
  end
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Find File/Folder by Path

SDK Method

Files::File.find

Return Object

File

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
path
string
Required
Path to operate on.
preview_size
string
Request a preview size. Can be small (default), large, xlarge, or pdf.
with_previews
boolean
Include file preview information?
with_priority_color
boolean
Include file priority color information?

Example Request

begin
  file = Files::File.find(path, 
    with_previews: false
  )
  # Operate on file
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

List Folders by Path

For historical reasons, and to maintain compatibility with a variety of other cloud-based MFT and EFSS services, Folders will always be listed before Files when listing a Folder. This applies regardless of the sorting parameters you provide. These will be used, after the initial sort application of Folders before Files.

SDK Method

Files::Folder.list_for

Return Object

List<File>

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
path
string
Required
Path to operate on.
preview_size
string
Request a preview size. Can be small (default), large, xlarge, or pdf.
search
string
If specified, will search the folders/files list by name. Ignores text before last /. This is the same API used by the search bar in the web UI when running 'Search This Folder'. Search results are a best effort, not real time, and not guaranteed to perfectly match the latest folder listing. Results may be truncated if more than 1,000 possible matches exist. This field should only be used for ad-hoc (human) searching, and not as part of an automated process.
search_custom_metadata_key
string
If provided, the search string in search will search for files where this custom metadata key matches the value sent in search. Set this to * to allow any metadata key to match the value sent in search.
search_all
boolean
Search entire site? If true, we will search the entire site. Do not provide a path when using this parameter. The search term must contain at least 3 characters after replacing * with spaces and trimming leading and trailing whitespace. This is the same API used by the search bar in the web UI when running 'Search All Files'. Search results are a best effort, not real time, and not guaranteed to match every file. This field should only be used for ad-hoc (human) searching, and not as part of an automated process.
with_previews
boolean
Include file previews?
with_priority_color
boolean
Include file priority color information?
type
string
Type of objects to return. Can be folder or file.
modified_at_datetime
string
If provided, will only return files/folders modified after this time. Can be used only in combination with type filter.

Additional Arguments

Example Request

begin
  files = Files::Folder.list_for(path, 
    search: "some-partial-filename"
  )
  files.auto_paging_each do |file|
    # Operate on file
  end
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Create Folder

SDK Method

Files::Folder.create

Return Object

File

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
path
string
Required
Path to operate on.
mkdir_parents
boolean
Create parent directories if they do not exist?
provided_mtime
string
User provided modification time.

Example Request

begin
  file = Files::Folder.create(path, 
    mkdir_parents: false
  )
  # Operate on file
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Update File/Folder Metadata

SDK Method

file.update

Return Object

File

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
custom_metadata
object
Custom metadata map. Replaces existing metadata; an empty map clears it. Requires Full or Admin permission. Uploaders with Write permission can supply custom metadata when completing an upload instead.
provided_mtime
string
Modified time of file.
priority_color
string
Priority/Bookmark color of file.

Example Request

begin
  # Find the file object by its path.
  file = Files::File.find(path)
  file.update(
    custom_metadata: {"department":"finance"}
  )
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Delete File/Folder

SDK Method

file.delete

Return Object

nil

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
recursive
boolean
If true, will recursively delete folders. Otherwise, will error on non-empty folders.

Example Request

begin
  # Find the file object by its path.
  file = Files::File.find(path)
  file.delete(
    recursive: false
  )
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Create a ZIP from one or more paths and save it to a destination path

SDK Method

Files::File.zip

Return Object

FileAction

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
paths
array(string)
Required
Paths to include in the ZIP.
destination
string
Required
Destination file path for the ZIP.
archive_format
string
Archive format to create.
Possible values: zip, tar, tar.gz, tgz
overwrite
boolean
Overwrite existing file in the destination?

Example Request

begin
  file_action = Files::File.zip(
    paths: "paths",
    destination: "destination"
  )
  # Operate on file_action
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Extract a ZIP file to a destination folder

SDK Method

file.unzip

Return Object

FileAction

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
destination
string
Required
Destination folder path for extracted files.
filename
string
Optional single entry filename to extract.
overwrite
boolean
Overwrite existing files in the destination?

Example Request

begin
  # Find the file object by its path.
  file = Files::File.find(path)
  file.unzip(
    destination: "destination"
  )
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Encrypt a file with GPG and save it to a destination path

SDK Method

file.gpg_encrypt

Return Object

FileAction

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
destination
string
Required
Destination file path for the encrypted file.
gpg_key_ids
array(int64)
GPG Key IDs to encrypt with.
gpg_key_partner_id
int64
Partner ID whose GPG keys should be used for encryption.
signing_key_id
int64
Optional GPG Key ID to sign with.
armor
boolean
Output ASCII-armored encrypted data.
overwrite
boolean
Overwrite existing file in the destination?

Example Request

begin
  # Find the file object by its path.
  file = Files::File.find(path)
  file.gpg_encrypt(
    destination: "destination"
  )
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Decrypt a GPG-encrypted file and save it to a destination path

SDK Method

file.gpg_decrypt

Return Object

FileAction

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
destination
string
Required
Destination file path for the decrypted file.
gpg_key_ids
array(int64)
GPG Key IDs to decrypt with. If omitted, every accessible private GPG key in the source workspace is used.
gpg_key_partner_id
int64
Partner ID whose GPG keys should be used for decryption.
use_all_private_keys
boolean
Use every accessible private GPG key in the source workspace for decryption.
ignore_mdc_error
boolean
Ignore errors from the MDC (modification detection code) check.
overwrite
boolean
Overwrite existing file in the destination?

Example Request

begin
  # Find the file object by its path.
  file = Files::File.find(path)
  file.gpg_decrypt(
    destination: "destination"
  )
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Transform a file and save the output to a destination path

SDK Method

file.transform

Return Object

FileAction

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
destination
string
Required
Destination file path for the transformed output.
transform_type
string
Required
Transform type. Supported values are image_convert, document_convert, and files_transform_script_execute.
target_format
string
Required
Destination format to create.
script
string
Files TransformScript source. Required when transform_type is files_transform_script_execute.
width
int64
Maximum output width for image_convert.
height
int64
Maximum output height for image_convert.
overwrite
boolean
Overwrite existing file in the destination?

Example Request

begin
  # Find the file object by its path.
  file = Files::File.find(path)
  file.transform(
    destination: "destination",
    transform_type: "transform_type",
    target_format: "target_format"
  )
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Move File/Folder

SDK Method

file.move

Return Object

FileAction

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
destination
string
Required
Move destination path.
overwrite
boolean
Overwrite existing file(s) in the destination?

Example Request

begin
  # Find the file object by its path.
  file = Files::File.find(path)
  file.move(
    destination: "destination"
  )
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Copy File/Folder

SDK Method

file.copy

Return Object

FileAction

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
destination
string
Required
Copy destination path.
copy_behaviors
boolean
If copying a folder, also copy supported behaviors, email notification subscriptions, and per-folder branding to the destination folder tree?
structure
boolean
Copy structure only?
overwrite
boolean
Overwrite existing file(s) in the destination?

Example Request

begin
  # Find the file object by its path.
  file = Files::File.find(path)
  file.copy(
    destination: "destination"
  )
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Delete File/Folder and return its File Action. A pending or processing deletion continues in the background after this returns; check its File Migration for completion. Waiting for the File Migration does not cancel the deletion

SDK Method

file.begin_delete

Return Object

FileAction

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
recursive
boolean
If true, will recursively delete folders. Otherwise, will error on non-empty folders.

Example Request

begin
  # Find the file object by its path.
  file = Files::File.find(path)
  file.begin_delete(
    recursive: false
  )
rescue Files::NotAuthenticatedError => e
  puts "Authentication Error Occurred (#{e.class.to_s}): " + e.message
rescue Files::Error => e
  puts "Unknown Error Occurred (#{e.class.to_s}): " + e.message
end

Upload to External Destinations

These SDK helpers upload files into external destinations without requiring callers to assemble destination-specific paths manually.

DestinationSDK MethodID Parameter
Remote Serverupload_to_remote_serverremote_server_id
Snapshotupload_to_snapshotsnapshot_id
Child Siteupload_to_child_sitesite_id

Example Request

Files::File.upload_to_remote_server(local_path, remote_server_id, "remote/path/to/file.txt", params: { mkdir_parents: true })
Files::File.upload_to_snapshot(local_path, snapshot_id, "remote/path/to/file.txt")
Files::File.upload_to_child_site(local_path, site_id, "remote/path/to/file.txt")

Copy to External Destinations

These SDK helpers copy files or folders into external destinations without requiring callers to assemble destination-specific paths manually.

DestinationSDK MethodID Parameter
Remote Servercopy_to_remote_serverremote_server_id
Snapshotcopy_to_snapshotsnapshot_id
Child Sitecopy_to_child_sitesite_id

Example Request

file.copy_to_remote_server(remote_server_id, "remote/path/to/file.txt", overwrite: true)
file.copy_to_snapshot(snapshot_id, "remote/path/to/file.txt")
file.copy_to_child_site(site_id, "remote/path/to/file.txt")

Move to External Destinations

These SDK helpers move files or folders into external destinations without requiring callers to assemble destination-specific paths manually.

DestinationSDK MethodID Parameter
Remote Servermove_to_remote_serverremote_server_id
Snapshotmove_to_snapshotsnapshot_id
Child Sitemove_to_child_sitesite_id

Example Request

file.move_to_remote_server(remote_server_id, "remote/path/to/file.txt", overwrite: true)
file.move_to_snapshot(snapshot_id, "remote/path/to/file.txt")
file.move_to_child_site(site_id, "remote/path/to/file.txt")

The File Object

Some of the methods above return a File object. The attributes of this object are listed below.

AttributeDescription
path
string
File/Folder path. This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters.
created_by_id
int64
User ID of the User who created the file/folder
created_by_api_key_id
int64
ID of the API key that created the file/folder
created_by_as2_incoming_message_id
int64
ID of the AS2 Incoming Message that created the file/folder
created_by_automation_id
int64
ID of the Automation that created the file/folder
created_by_bundle_registration_id
int64
ID of the Bundle Registration that created the file/folder
created_by_inbox_id
int64
ID of the Inbox that created the file/folder
created_by_remote_server_id
int64
ID of the Remote Server that created the file/folder
created_by_sync_id
int64
ID of the Sync that created the file/folder
custom_metadata
object
Custom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value.
display_name
string
File/Folder display name
type
string
Type: directory or file.
size
int64
File/Folder size
created_at
date-time
File created date/time
last_modified_by_id
int64
User ID of the User who last modified the file/folder
last_modified_by_api_key_id
int64
ID of the API key that last modified the file/folder
last_modified_by_automation_id
int64
ID of the Automation that last modified the file/folder
last_modified_by_bundle_registration_id
int64
ID of the Bundle Registration that last modified the file/folder
last_modified_by_remote_server_id
int64
ID of the Remote Server that last modified the file/folder
last_modified_by_sync_id
int64
ID of the Sync that last modified the file/folder
mtime
date-time
File last modified date/time, according to the server. This is the timestamp of the last Files.com operation of the file, regardless of what modified timestamp was sent.
provided_mtime
date-time
File last modified date/time, according to the client who set it. Files.com allows desktop, FTP, SFTP, and WebDAV clients to set modified at times. This allows Desktop<->Cloud syncing to preserve modified at times.
crc32
string
File CRC32 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
md5
string
File MD5 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
sha1
string
File SHA1 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
sha256
string
File SHA256 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
mime_type
string
MIME Type. This is determined by the filename extension and is not stored separately internally.
region
string
Region location
permissions
string
A short string representing the current user's permissions. Can be r (Read),w (Write),d (Delete), l (List) or any combination
subfolders_locked?
boolean
Are subfolders locked and unable to be modified?
is_locked
boolean
Is this folder locked and unable to be modified?
download_uri
string
Link to download file. Provided only in response to a download request.
direct_connection_info
DirectConnectionInfo
Optional direct connection information for direct Agent transfer attempts
priority_color
string
Bookmark/priority color of file/folder
preview_id
int64
File preview ID
preview
Preview
File preview

custom_metadata

Custom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value.

Value typeDescription
object of string valuesCustom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value. At most 32 keys.

Example custom_metadata

{
  "department": "finance"
}