SFTP Host Keys

An SFTP Host Key is a cryptographic key used to verify the identity of the server during an SFTP connection. This allows the client to be sure that it is connecting to the intended server, preventing man-in-the-middle attacks and ensuring secure communication between the client and Files.com.

Files.com allows you to provide custom SFTP Host Keys, which is particularly useful when migrating to Files.com from an existing SFTP server, allowing the Files.com platform to match your previously-installed host key for a seamless transition.

List SFTP Host Keys

SDK Method

\Files\Model\SftpHostKey::list;

Return Object

SftpHostKey[]

Authorization Requirement

Requires either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Additional Arguments

Example Request

try {
  $sftp_host_keys = \Files\Model\SftpHostKey::list();
  foreach ($sftp_host_keys as $sftp_host_key) {
    // Operate on $sftp_host_key
  }
} catch (\Files\NotAuthenticated\InvalidUsernameOrPasswordException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Show SFTP Host Key

SDK Method

\Files\Model\SftpHostKey::find;

Return Object

SftpHostKey

Authorization Requirement

Requires either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Method Arguments

ArgumentDescription
id
int64
Required
Sftp Host Key ID.

Example Request

try {
  $sftp_host_key = \Files\Model\SftpHostKey::find($id);
  // Operate on $sftp_host_key
} catch (\Files\NotAuthenticated\InvalidUsernameOrPasswordException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Create SFTP Host Key

SDK Method

\Files\Model\SftpHostKey::create;

Return Object

SftpHostKey

Authorization Requirement

Requires either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Method Arguments

ArgumentDefaultDescription
active
boolean
falseIf true, use this SFTP Host Key.
name
string
The friendly name of this SFTP Host Key.
private_key
string
The private key data.

Example Request

try {
  $sftp_host_key = \Files\Model\SftpHostKey::create([
    'active' => true
  ]);
  // Operate on $sftp_host_key
} catch (\Files\NotAuthenticated\InvalidUsernameOrPasswordException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Update SFTP Host Key

SDK Method

$sftp_host_key->update;

Return Object

SftpHostKey

Authorization Requirement

Requires either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Method Arguments

ArgumentDescription
active
boolean
If true, use this SFTP Host Key.
name
string
The friendly name of this SFTP Host Key.
private_key
string
The private key data.

Example Request

try {
  // Find the sftp_host_key object by its id.
  $sftp_host_key = \Files\Model\SftpHostKey::find(id);
  $sftp_host_key->update([
    'active' => true
  ]);
} catch (\Files\NotAuthenticated\InvalidUsernameOrPasswordException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Delete SFTP Host Key

SDK Method

$sftp_host_key->delete;

Return Object

No return value.

Authorization Requirement

Requires either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Example Request

try {
  // Find the sftp_host_key object by its id.
  $sftp_host_key = \Files\Model\SftpHostKey::find(id);
  $sftp_host_key->delete();
} catch (\Files\NotAuthenticated\InvalidUsernameOrPasswordException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

The SftpHostKey Object

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

AttributeDescription
active
boolean
If true, use this SFTP Host Key.
id
int64
SFTP Host Key ID
name
string
The friendly name of this SFTP Host Key.
key_type
string
SSH key type
fingerprint_md5
string
MD5 Fingerprint of the public key
fingerprint_sha256
string
SHA256 Fingerprint of the public key