Error Structure as json can be found here.
- Load Directory
- Open File
- Create File
- Delete File
- Rename File
- Copy File
- Move File
- Create Directory
- Delete Directory
- Rename Directory
- Copy Directory
- Move Directory
- Build Preview
- Download and Open File
- Cleanup SFTP Temp Files
Lists the contents of a directory on the SFTP server.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationdirectory: String - The directory path to list (use "." for current directory)
- Ok(String) - JSON string containing the directory structure with files and subdirectories
- Err(String) - An error message if connection fails, authentication fails, or directory doesn't exist
useEffect(() => {
const loadDirectory = async () => {
try {
const result = await invoke("load_dir", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
directory: "."
});
const directoryData = JSON.parse(result);
console.log("Directory contents:", directoryData);
} catch (error) {
console.error("Error loading directory:", error);
}
};
loadDirectory();
}, []);Reads the contents of a file from the SFTP server.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationfile_path: String - The path to the file to read
- Ok(String) - The contents of the file as a string
- Err(String) - An error message if connection fails, authentication fails, or file doesn't exist
const readFile = async () => {
try {
const content = await invoke("open_file_sftp", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
file_path: "example.txt"
});
console.log("File content:", content);
} catch (error) {
console.error("Error reading file:", error);
}
};Creates a new empty file on the SFTP server.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationfile_path: String - The path where the new file should be created
- Ok(String) - Success message with the file path
- Err(String) - An error message if connection fails, authentication fails, or file creation fails
const createFile = async () => {
try {
const result = await invoke("create_file_sftp", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
file_path: "new_file.txt"
});
console.log("Success:", result);
} catch (error) {
console.error("Error creating file:", error);
}
};Deletes a file from the SFTP server.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationfile_path: String - The path to the file to delete
- Ok(String) - Success message with the deleted file path
- Err(String) - An error message if connection fails, authentication fails, or file doesn't exist
const deleteFile = async () => {
try {
const result = await invoke("delete_file_sftp", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
file_path: "file_to_delete.txt"
});
console.log("Success:", result);
} catch (error) {
console.error("Error deleting file:", error);
}
};Renames a file on the SFTP server.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationold_path: String - The current path of the filenew_path: String - The new path/name for the file
- Ok(String) - Success message with old and new paths
- Err(String) - An error message if connection fails, authentication fails, or file doesn't exist
const renameFile = async () => {
try {
const result = await invoke("rename_file_sftp", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
old_path: "old_name.txt",
new_path: "new_name.txt"
});
console.log("Success:", result);
} catch (error) {
console.error("Error renaming file:", error);
}
};Copies a file on the SFTP server.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationsource_path: String - The path to the source filedestination_path: String - The path where the file should be copied
- Ok(String) - Success message with source and destination paths
- Err(String) - An error message if connection fails, authentication fails, or source file doesn't exist
const copyFile = async () => {
try {
const result = await invoke("copy_file_sftp", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
source_path: "source.txt",
destination_path: "copy.txt"
});
console.log("Success:", result);
} catch (error) {
console.error("Error copying file:", error);
}
};Moves a file on the SFTP server.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationsource_path: String - The current path of the filedestination_path: String - The new path for the file
- Ok(String) - Success message with source and destination paths
- Err(String) - An error message if connection fails, authentication fails, or source file doesn't exist
const moveFile = async () => {
try {
const result = await invoke("move_file_sftp", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
source_path: "file.txt",
destination_path: "moved/file.txt"
});
console.log("Success:", result);
} catch (error) {
console.error("Error moving file:", error);
}
};Creates a new directory on the SFTP server.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationdirectory_path: String - The path where the new directory should be created
- Ok(String) - Success message with the directory path
- Err(String) - An error message if connection fails, authentication fails, or directory creation fails
const createDirectory = async () => {
try {
const result = await invoke("create_directory_sftp", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
directory_path: "new_folder"
});
console.log("Success:", result);
} catch (error) {
console.error("Error creating directory:", error);
}
};Deletes an empty directory from the SFTP server.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationdirectory_path: String - The path to the directory to delete
- Ok(String) - Success message with the deleted directory path
- Err(String) - An error message if connection fails, authentication fails, directory doesn't exist, or directory is not empty
const deleteDirectory = async () => {
try {
const result = await invoke("delete_directory_sftp", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
directory_path: "folder_to_delete"
});
console.log("Success:", result);
} catch (error) {
console.error("Error deleting directory:", error);
}
};Renames a directory on the SFTP server.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationold_path: String - The current path of the directorynew_path: String - The new path/name for the directory
- Ok(String) - Success message with old and new paths
- Err(String) - An error message if connection fails, authentication fails, or directory doesn't exist
const renameDirectory = async () => {
try {
const result = await invoke("rename_directory_sftp", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
old_path: "old_folder",
new_path: "new_folder"
});
console.log("Success:", result);
} catch (error) {
console.error("Error renaming directory:", error);
}
};Recursively copies a directory and its contents on the SFTP server.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationsource_path: String - The path to the source directorydestination_path: String - The path where the directory should be copied
- Ok(String) - Success message with source and destination paths
- Err(String) - An error message if connection fails, authentication fails, or source directory doesn't exist
const copyDirectory = async () => {
try {
const result = await invoke("copy_directory_sftp", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
source_path: "source_folder",
destination_path: "copied_folder"
});
console.log("Success:", result);
} catch (error) {
console.error("Error copying directory:", error);
}
};Moves a directory on the SFTP server.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationsource_path: String - The current path of the directorydestination_path: String - The new path for the directory
- Ok(String) - Success message with source and destination paths
- Err(String) - An error message if connection fails, authentication fails, or source directory doesn't exist
const moveDirectory = async () => {
try {
const result = await invoke("move_directory_sftp", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
source_path: "folder",
destination_path: "moved/folder"
});
console.log("Success:", result);
} catch (error) {
console.error("Error moving directory:", error);
}
};Generates a preview payload for a file or directory on the SFTP server, including type detection and metadata.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationfile_path: String - The path to the file or directory to preview
- Ok(PreviewPayload) - A JSON object describing the preview (text, image, pdf, folder, or unknown)
- Err(String) - An error message if connection fails, authentication fails, or file/directory doesn't exist
const preview = async () => {
try {
const result = await invoke("build_preview_sftp", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
file_path: "example.txt"
});
console.log("Preview payload:", result);
} catch (error) {
console.error("Error building preview:", error);
}
};Downloads a file from the SFTP server to a temporary local directory and optionally opens it with the default application.
host: String - The SFTP server hostname or IP addressport: u16 - The SFTP server port (typically 22)username: String - The username for authenticationpassword: String - The password for authenticationfile_path: String - The path to the file to downloadopen_file: Option - Whether to open the file after downloading (default: true)
- Ok(String) - The local path to the downloaded file, or a message indicating it was opened
- Err(String) - An error message if connection fails, authentication fails, or file doesn't exist
const downloadAndOpen = async () => {
try {
const result = await invoke("download_and_open_sftp_file", {
host: "localhost",
port: 2222,
username: "explorer",
password: "explorer",
file_path: "example.txt",
open_file: true
});
console.log("Download result:", result);
} catch (error) {
console.error("Error downloading file:", error);
}
};Removes temporary files downloaded from the SFTP server that are older than 24 hours from the local temp directory.
- None
- Ok(String) - A message indicating how many files were cleaned
- Err(String) - An error message if the temp directory cannot be read or cleaned
const cleanupTempFiles = async () => {
try {
const result = await invoke("cleanup_sftp_temp_files");
console.log("Cleanup result:", result);
} catch (error) {
console.error("Error cleaning up temp files:", error);
}
};- All SFTP commands require valid connection credentials (host, port, username, password)
- The default SFTP port is typically 22, but can vary depending on server configuration
- File and directory paths are relative to the user's home directory on the SFTP server
- For directory operations like copy, the operation is recursive and will include all subdirectories and files
- Delete directory only works on empty directories - use recursive deletion if needed
- All commands return descriptive error messages for troubleshooting connection and operation issues