Traversio

Metadata And Listing

Resolve paths, inspect attributes, and read directory contents.

Path And Metadata Methods

The public metadata surface includes:

MethodPurpose
realPath(_:)Resolve a path according to the server
lstat(_:)Query metadata without following symlinks
stat(_:)Query metadata for the target path
fileSystemAttributes(_:)Query filesystem-level block, inode, and capacity information through OpenSSH [email protected]
listDirectory(_:)Return directory entries

Example:

let resolved = try await sftp.realPath(".")
let attributes = try await sftp.stat(resolved.filename)

print(resolved.filename)
print(attributes.permissions as Any)
print(attributes.size as Any)

If the server advertises OpenSSH [email protected] version 2, Traversio can also return filesystem-wide information for a path:

let filesystem = try await sftp.fileSystemAttributes("/var/log")

print(filesystem.blockSize)
print(filesystem.freeBlocks)
print(filesystem.maximumFilenameLength)
print(filesystem.flags.contains(.readOnly))

If you already have a file handle open, the same metadata family is available without going back through a path:

let handle = try await sftp.openFile("/var/log/system.log")
let attributes = try await handle.stat()
let filesystem = try await handle.fileSystemAttributes()

print(attributes.size as Any)
print(filesystem.blockSize)

try await handle.close()

Directory Listing

Use listDirectory(_:) to collect the directory entries under a path:

let entries = try await sftp.listDirectory(".")

for entry in entries {
    print(entry.filename)
}

The high-level convenience method opens the directory handle, reads until completion, and closes the handle before returning.

Understanding SSHSFTPFileAttributes

The public attributes type carries:

  • flags
  • size
  • userID
  • groupID
  • permissions
  • accessTime
  • modificationTime
  • extensions

Example:

let attributes = try await sftp.lstat("/tmp/example.txt")

print(attributes.flags)
print(attributes.permissions as Any)
print(attributes.modificationTime as Any)

Name Entries

SSHSFTPNameEntry represents one entry returned by directory listing, realPath, or readLink:

  • filename
  • longName
  • attributes

This lets you keep the path string and the associated metadata together instead of bouncing between separate calls immediately.

SSHSFTPFileSystemAttributes

fileSystemAttributes(_:) returns SSHSFTPFileSystemAttributes, which currently carries:

  • blockSize
  • fundamentalBlockSize
  • totalBlocks
  • freeBlocks
  • availableBlocks
  • totalFileNodes
  • freeFileNodes
  • availableFileNodes
  • fileSystemID
  • flags
  • maximumFilenameLength

flags uses SSHSFTPFileSystemFlags and currently exposes:

  • .readOnly
  • .noSetUserID

If the server does not advertise the OpenSSH extension version required for the path or handle form, Traversio fails the call instead of guessing.

On this page