Skip to content

Automate browser based workflows with AI

feat(SKY-12135): add SFTP target to the file upload (Cloud Storage) block (#7268)

Suchintan702d1095e679
diff --git a/pyproject.toml b/pyproject.toml
index 39115c960..4e44b5d98 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -45,6 +45,7 @@ local = [
"alembic>=1.12.1,<2",
"PyJWT[crypto]>=2.13.0,<3",
"aioboto3>=14.3.0,<15",
+ "asyncssh>=2.14.2,<3",
"asyncache>=0.3.1,<0.4",
"filetype>=1.2.0,<2",
"fuzzysearch>=0.8,<1",
@@ -118,6 +119,7 @@ server = [
"alembic>=1.12.1,<2",
"PyJWT[crypto]>=2.13.0,<3",
"aioboto3>=14.3.0,<15",
+ "asyncssh>=2.14.2,<3",
"asyncache>=0.3.1,<0.4",
"types-toml>=0.10.8.7,<0.11",
"filetype>=1.2.0,<2",
diff --git a/skyvern-frontend/src/routes/workflows/editor/helpContent.ts b/skyvern-frontend/src/routes/workflows/editor/helpContent.ts
index f4248872a..c2ed832fa 100644
--- a/skyvern-frontend/src/routes/workflows/editor/helpContent.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/helpContent.ts
@@ -155,7 +155,7 @@ export const helpTooltips = {
...baseHelpTooltipContent,
path: "The path of the folder to upload the files to.",
storage_type:
- "The type of storage to upload the file to. Currently only S3 is supported. Please contact us if you'd like to integrate other storage types.",
+ "The type of storage to upload the file to. S3, Azure Blob Storage, Google Drive, and SFTP are supported.",
s3_bucket: "The S3 bucket to upload the file to.",
aws_access_key_id: "The AWS access key ID to use to upload the file to S3.",
aws_secret_access_key:
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/FileUploadNode/FileUploadEditor.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/FileUploadNode/FileUploadEditor.tsx
index 16db7d675..119d4095b 100644
--- a/skyvern-frontend/src/routes/workflows/editor/nodes/FileUploadNode/FileUploadEditor.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/FileUploadNode/FileUploadEditor.tsx
@@ -49,6 +49,14 @@ function FileUploadEditorBody({
azureBlobContainerName,
googleCredentialId,
googleDriveFolderId,
+ sftpHost,
+ sftpPort,
+ sftpUsername,
+ sftpPassword,
+ sftpPrivateKey,
+ sftpPrivateKeyPassphrase,
+ sftpRemotePath,
+ sftpHostKey,
} = data;
const update = useUpdate<FileUploadNodeData>({ id: blockId, editable });
@@ -63,7 +71,9 @@ function FileUploadEditorBody({
value={storageType}
onValueChange={(value) =>
value &&
- update({ storageType: value as "s3" | "azure" | "google_drive" })
+ update({
+ storageType: value as "s3" | "azure" | "google_drive" | "sftp",
+ })
}
disabled={!editable}
>
@@ -74,6 +84,7 @@ function FileUploadEditorBody({
<SelectItem value="s3">Amazon S3</SelectItem>
<SelectItem value="azure">Azure Blob Storage</SelectItem>
<SelectItem value="google_drive">Google Drive</SelectItem>
+ <SelectItem value="sftp">SFTP</SelectItem>
</SelectContent>
</Select>
</div>
@@ -260,6 +271,117 @@ function FileUploadEditorBody({
</div>
</>
)}
+
+ {storageType === "sftp" && (
+ <>
+ <div className="space-y-2">
+ <div className="flex items-center gap-2">
+ <Label className="text-sm text-slate-400">SFTP Host</Label>
+ <HelpTooltip content="The SFTP host to upload files to." />
+ </div>
+ <WorkflowBlockInputTextarea
+ nodeId={blockId}
+ onChange={(value) => update({ sftpHost: value })}
+ value={sftpHost ?? ""}
+ className="nopan text-xs"
+ />
+ </div>
+ <div className="space-y-2">
+ <div className="flex items-center gap-2">
+ <Label className="text-sm text-slate-400">Port</Label>
+ <HelpTooltip content="Numeric only — template values are not supported. Defaults to 22 if left blank." />
+ </div>
+ <WorkflowBlockInputTextarea
+ nodeId={blockId}
+ onChange={(value) =>
+ update({ sftpPort: value.replace(/[^0-9]/g, "") })
+ }
+ value={sftpPort ?? ""}
+ className="nopan text-xs"
+ />
+ </div>
+ <div className="space-y-2">
+ <div className="flex items-center gap-2">
+ <Label className="text-sm text-slate-400">Username</Label>
+ <HelpTooltip content="The SFTP username." />
+ </div>
+ <WorkflowBlockInputTextarea
+ nodeId={blockId}
+ onChange={(value) => update({ sftpUsername: value })}
+ value={sftpUsername ?? ""}
+ className="nopan text-xs"
+ />
+ </div>
+ <div className="space-y-2">
+ <div className="flex items-center gap-2">
+ <Label className="text-sm text-slate-400">Password</Label>
+ <HelpTooltip content="Password auth. Leave blank if using a private key. Reference a secret parameter for security." />
+ </div>
+ <WorkflowBlockInput
+ nodeId={blockId}
+ type="password"
+ onChange={(value) => update({ sftpPassword: value })}
+ value={sftpPassword ?? ""}
+ className="nopan text-xs"
+ />
+ </div>
+ <div className="space-y-2">
+ <div className="flex items-center gap-2">
+ <Label className="text-sm text-slate-400">Private Key</Label>
+ <HelpTooltip content="PEM private key for key-based auth. Leave blank if using a password. Reference a secret parameter for security." />
+ </div>
+ <WorkflowBlockInputTextarea
+ nodeId={blockId}
+ onChange={(value) => update({ sftpPrivateKey: value })}
+ value={sftpPrivateKey ?? ""}
+ className="nopan text-xs"
+ />
+ </div>
+ <div className="space-y-2">
+ <div className="flex items-center gap-2">
+ <Label className="text-sm text-slate-400">
+ Private Key Passphrase (Optional)
+ </Label>
+ <HelpTooltip content="Optional passphrase for the private key." />
+ </div>
+ <WorkflowBlockInput
+ nodeId={blockId}
+ type="password"
+ onChange={(value) => update({ sftpPrivateKeyPassphrase: value })}
+ value={sftpPrivateKeyPassphrase ?? ""}
+ className="nopan text-xs"
+ />
+ </div>
+ <div className="space-y-2">
+ <div className="flex items-center gap-2">
+ <Label className="text-sm text-slate-400">
+ (Optional) Remote Directory
+ </Label>
+ <HelpTooltip content="Remote directory to upload into. Created if it does not exist. Defaults to the login directory." />
+ </div>
+ <WorkflowBlockInputTextarea
+ nodeId={blockId}
+ onChange={(value) => update({ sftpRemotePath: value })}
+ value={sftpRemotePath ?? ""}
+ className="nopan text-xs"
+ />
+ </div>
+ <div className="space-y-2">
+ <div className="flex items-center gap-2">
+ <Label className="text-sm text-slate-400">
+ (Optional) Host Key
+ </Label>
+ <HelpTooltip content="If blank, the server's host key is NOT verified and the connection can be intercepted (MITM). Pin a host key (e.g. 'ssh-ed25519 AAAA...') for untrusted networks." />
+ </div>
+ <WorkflowBlockInputTextarea
+ nodeId={blockId}
+ onChange={(value) => update({ sftpHostKey: value })}
+ value={sftpHostKey ?? ""}
+ className="nopan text-xs"
+ />
+ </div>
+ </>
+ )}
</div>
);
}
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/FileUploadNode/types.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/FileUploadNode/types.ts
index 6a41f468a..bdc6cd50f 100644
--- a/skyvern-frontend/src/routes/workflows/editor/nodes/FileUploadNode/types.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/FileUploadNode/types.ts
@@ -5,7 +5,7 @@ import { debuggableWorkflowBlockTypes } from "@/routes/workflows/types/workflowT
export type FileUploadNodeData = NodeBaseData & {
path: string;
editable: boolean;
- storageType: "s3" | "azure" | "google_drive";
+ storageType: "s3" | "azure" | "google_drive" | "sftp";
s3Bucket: string | null;
awsAccessKeyId: string | null;
awsSecretAccessKey: string | null;
@@ -15,6 +15,14 @@ export type FileUploadNodeData = NodeBaseData & {
azureBlobContainerName: string | null;
googleCredentialId: string | null;
googleDriveFolderId: string | null;
+ sftpHost: string | null;
+ sftpPort: string | null;
+ sftpUsername: string | null;
+ sftpPassword: string | null;
+ sftpPrivateKey: string | null;
+ sftpPrivateKeyPassphrase: string | null;
+ sftpRemotePath: string | null;
+ sftpHostKey: string | null;
};
export type FileUploadNode = Node<FileUploadNodeData, "fileUpload">;
@@ -34,6 +42,14 @@ export const fileUploadNodeDefaultData: FileUploadNodeData = {
azureBlobContainerName: null,
googleCredentialId: null,
googleDriveFolderId: null,
+ sftpHost: null,
+ sftpPort: null,
+ sftpUsername: null,
+ sftpPassword: null,
+ sftpPrivateKey: null,
+ sftpPrivateKeyPassphrase: null,
+ sftpRemotePath: null,
+ sftpHostKey: null,
continueOnFailure: false,
model: null,
} as const;
diff --git a/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/FileUploadBlockForm.tsx b/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/FileUploadBlockForm.tsx
index 727ea610a..30404f326 100644
--- a/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/FileUploadBlockForm.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/FileUploadBlockForm.tsx
@@ -38,6 +38,14 @@ function FileUploadBlockFormBody({
azureBlobContainerName,
googleCredentialId,
googleDriveFolderId,
+ sftpHost,
+ sftpPort,
+ sftpUsername,
+ sftpPassword,
+ sftpPrivateKey,
+ sftpPrivateKeyPassphrase,
+ sftpRemotePath,
+ sftpHostKey,
} = node.data;
const value = useMemo(
@@ -53,6 +61,14 @@ function FileUploadBlockFormBody({
azureBlobContainerName,
googleCredentialId,
googleDriveFolderId,
+ sftpHost,
+ sftpPort,
+ sftpUsername,
+ sftpPassword,
+ sftpPrivateKey,
+ sftpPrivateKeyPassphrase,
+ sftpRemotePath,
+ sftpHostKey,
}),
[
storageType,
@@ -66,6 +82,14 @@ function FileUploadBlockFormBody({
azureBlobContainerName,
googleCredentialId,
googleDriveFolderId,
+ sftpHost,
+ sftpPort,
+ sftpUsername,
+ sftpPassword,
+ sftpPrivateKey,
+ sftpPrivateKeyPassphrase,
+ sftpRemotePath,
+ sftpHostKey,
],
);
const { commit } = useDebouncedSidebarSave({
diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
index b72c3af30..03c1164a9 100644
--- a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
@@ -1081,6 +1081,14 @@ function convertToNode(
azureBlobContainerName: block.azure_blob_container_name ?? "",
googleCredentialId: block.google_credential_id ?? "",
googleDriveFolderId: block.google_drive_folder_id ?? "",
+ sftpHost: block.sftp_host ?? "",
+ sftpPort: block.sftp_port != null ? String(block.sftp_port) : "",
+ sftpUsername: block.sftp_username ?? "",
+ sftpPassword: block.sftp_password ?? "",
+ sftpPrivateKey: block.sftp_private_key ?? "",
+ sftpPrivateKeyPassphrase: block.sftp_private_key_passphrase ?? "",
+ sftpRemotePath: block.sftp_remote_path ?? "",
+ sftpHostKey: block.sftp_host_key ?? "",
},
};
}
@@ -3085,6 +3093,17 @@ function getWorkflowBlock(
azure_blob_container_name: node.data.azureBlobContainerName ?? "",
google_credential_id: node.data.googleCredentialId ?? "",
google_drive_folder_id: node.data.googleDriveFolderId ?? "",
+ sftp_host: node.data.sftpHost ?? "",
+ sftp_port:
+ node.data.sftpPort && Number.isFinite(Number(node.data.sftpPort))
+ ? Number(node.data.sftpPort)
+ : null,
+ sftp_username: node.data.sftpUsername ?? "",
+ sftp_password: node.data.sftpPassword ?? "",
+ sftp_private_key: node.data.sftpPrivateKey ?? "",
+ sftp_private_key_passphrase: node.data.sftpPrivateKeyPassphrase ?? "",
+ sftp_remote_path: node.data.sftpRemotePath ?? "",
+ sftp_host_key: node.data.sftpHostKey ?? "",
};
}
case "fileParser": {
@@ -4441,6 +4460,14 @@ function convertBlocksToBlockYAML(
azure_blob_container_name: block.azure_blob_container_name ?? "",
google_credential_id: block.google_credential_id ?? "",
google_drive_folder_id: block.google_drive_folder_id ?? "",
+ sftp_host: block.sftp_host ?? "",
+ sftp_port: block.sftp_port ?? null,
+ sftp_username: block.sftp_username ?? "",
+ sftp_password: block.sftp_password ?? "",
+ sftp_private_key: block.sftp_private_key ?? "",
+ sftp_private_key_passphrase: block.sftp_private_key_passphrase ?? "",
+ sftp_remote_path: block.sftp_remote_path ?? "",
+ sftp_host_key: block.sftp_host_key ?? "",
};
return blockYaml;
}
diff --git a/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts b/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts
index ebaf3e499..85e32bbb2 100644
--- a/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts
+++ b/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts
@@ -422,7 +422,7 @@ export type UploadToS3Block = WorkflowBlockBase & {
export type FileUploadBlock = WorkflowBlockBase & {
block_type: "file_upload";
path: string;
- storage_type: "s3" | "azure" | "google_drive";
+ storage_type: "s3" | "azure" | "google_drive" | "sftp";
s3_bucket: string | null;
region_name: string | null;
aws_access_key_id: string | null;
@@ -432,6 +432,14 @@ export type FileUploadBlock = WorkflowBlockBase & {
azure_blob_container_name: string | null;
google_credential_id: string | null;
google_drive_folder_id: string | null;
+ sftp_host: string | null;
+ sftp_port: number | null;
+ sftp_username: string | null;
+ sftp_password: string | null;
+ sftp_private_key: string | null;
+ sftp_private_key_passphrase: string | null;
+ sftp_remote_path: string | null;
+ sftp_host_key: string | null;
};
export type SendEmailBlock = WorkflowBlockBase & {
diff --git a/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts b/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts
index a706b71ac..8fcb52b23 100644
--- a/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts
+++ b/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts
@@ -357,6 +357,14 @@ export type FileUploadBlockYAML = BlockYAMLBase & {
azure_blob_container_name?: string | null;
google_credential_id?: string | null;
google_drive_folder_id?: string | null;
+ sftp_host?: string | null;
+ sftp_port?: number | null;
+ sftp_username?: string | null;
+ sftp_password?: string | null;
+ sftp_private_key?: string | null;
+ sftp_private_key_passphrase?: string | null;
+ sftp_remote_path?: string | null;
+ sftp_host_key?: string | null;
};
export type SendEmailBlockYAML = BlockYAMLBase & {
diff --git a/skyvern/client/types/file_storage_type.py b/skyvern/client/types/file_storage_type.py
index f9c20d15a..b1d0b391f 100644
--- a/skyvern/client/types/file_storage_type.py
+++ b/skyvern/client/types/file_storage_type.py
@@ -2,4 +2,4 @@
import typing
-FileStorageType = typing.Union[typing.Literal["s3", "azure", "google_drive"], typing.Any]
+FileStorageType = typing.Union[typing.Literal["s3", "azure", "google_drive", "sftp"], typing.Any]
diff --git a/skyvern/client/types/file_upload_block.py b/skyvern/client/types/file_upload_block.py
index 6cc3e747d..5c0e93e60 100644
--- a/skyvern/client/types/file_upload_block.py
+++ b/skyvern/client/types/file_upload_block.py
@@ -37,6 +37,14 @@ class FileUploadBlock(UniversalBaseModel):
azure_blob_container_name: typing.Optional[str] = None
google_credential_id: typing.Optional[str] = None
google_drive_folder_id: typing.Optional[str] = None
+ sftp_host: typing.Optional[str] = None
+ sftp_port: typing.Optional[int] = None
+ sftp_username: typing.Optional[str] = None
+ sftp_password: typing.Optional[str] = None
+ sftp_private_key: typing.Optional[str] = None
+ sftp_private_key_passphrase: typing.Optional[str] = None
+ sftp_remote_path: typing.Optional[str] = None
+ sftp_host_key: typing.Optional[str] = None
path: typing.Optional[str] = None
if IS_PYDANTIC_V2:
diff --git a/skyvern/client/types/file_upload_block_yaml.py b/skyvern/client/types/file_upload_block_yaml.py
index ae5d7bfde..2c2dd4881 100644
--- a/skyvern/client/types/file_upload_block_yaml.py
+++ b/skyvern/client/types/file_upload_block_yaml.py
@@ -35,6 +35,14 @@ class FileUploadBlockYaml(UniversalBaseModel):
azure_folder_path: typing.Optional[str] = None
google_credential_id: typing.Optional[str] = None
google_drive_folder_id: typing.Optional[str] = None
+ sftp_host: typing.Optional[str] = None
+ sftp_port: typing.Optional[int] = None
+ sftp_username: typing.Optional[str] = None
+ sftp_password: typing.Optional[str] = None
+ sftp_private_key: typing.Optional[str] = None
+ sftp_private_key_passphrase: typing.Optional[str] = None
+ sftp_remote_path: typing.Optional[str] = None
+ sftp_host_key: typing.Optional[str] = None
path: typing.Optional[str] = None
if IS_PYDANTIC_V2:
diff --git a/skyvern/config.py b/skyvern/config.py
index 6a13c85a2..5e597faaa 100644
--- a/skyvern/config.py
+++ b/skyvern/config.py
@@ -215,6 +215,9 @@ class Settings(BaseSettings):
ALLOWED_ORIGIN_REGEX: str | None = None
BLOCKED_HOSTS: list[str] = ["localhost"]
ALLOWED_HOSTS: list[str] = []
+ # SFTP uploads connect directly from the worker, so private/internal hosts are
+ # blocked by default; self-hosted deployments with internal SFTP targets can enable.
+ ALLOW_SFTP_INTERNAL_HOSTS: bool = False
# Format: "http://<username>:<password>@host:port, http://<username>:<password>@host:port, ...."
HOSTED_PROXY_POOL: str = ""
diff --git a/skyvern/core/script_generations/generate_script.py b/skyvern/core/script_generations/generate_script.py
index 7966cfe4a..2c3242948 100644
--- a/skyvern/core/script_generations/generate_script.py
+++ b/skyvern/core/script_generations/generate_script.py
@@ -2132,6 +2132,14 @@ def _build_file_upload_statement(block: dict[str, Any]) -> cst.SimpleStatementLi
"azure_blob_container_name",
"google_credential_id",
"google_drive_folder_id",
+ "sftp_host",
+ "sftp_port",
+ "sftp_username",
+ "sftp_password",
+ "sftp_private_key",
+ "sftp_private_key_passphrase",
+ "sftp_remote_path",
+ "sftp_host_key",
"path",
]:
if block.get(key) is not None:
diff --git a/skyvern/forge/agent_functions.py b/skyvern/forge/agent_functions.py
index e108a1610..f493edadb 100644
--- a/skyvern/forge/agent_functions.py
+++ b/skyvern/forge/agent_functions.py
@@ -39,7 +39,7 @@ from skyvern.forge.sdk.db.agent_db import AgentDB
from skyvern.forge.sdk.models import Step, StepStatus
from skyvern.forge.sdk.schemas.organizations import Organization
from skyvern.forge.sdk.schemas.tasks import Task, TaskStatus
-from skyvern.forge.sdk.services import google_drive_service, google_oauth_service
+from skyvern.forge.sdk.services import google_drive_service, google_oauth_service, sftp_service
from skyvern.forge.sdk.services.credentials import AuthenticatorTotpParseResult
from skyvern.forge.sdk.trace import traced
from skyvern.forge.sdk.workflow.models.block import BlockTypeVar
@@ -1548,6 +1548,24 @@ class AgentFunction:
)
return uploaded_file.web_view_link or f"https://drive.google.com/file/d/{uploaded_file.id}/view"
+ if destination.storage_type == FileStorageType.SFTP:
+ if not destination.sftp_host or not destination.sftp_username:
+ raise ValueError("SFTP destination is missing required fields")
+ if not destination.sftp_password and not destination.sftp_private_key:
+ raise ValueError("SFTP destination requires a password or private key")
+ await sftp_service.upload_file(
+ file_path=file_path,
+ host=destination.sftp_host,
+ port=destination.sftp_port if destination.sftp_port is not None else 22,
+ username=destination.sftp_username,
+ remote_path=destination.sftp_remote_path,
+ password=destination.sftp_password,
+ private_key=destination.sftp_private_key,
+ private_key_passphrase=destination.sftp_private_key_passphrase,
+ host_key=destination.sftp_host_key,
+ )
+ return destination.customer_uri
+
raise ValueError(f"Unsupported storage type: {destination.storage_type}")
@staticmethod
diff --git a/skyvern/forge/sdk/services/sftp_service.py b/skyvern/forge/sdk/services/sftp_service.py
new file mode 100644
index 000000000..42d92a377
--- /dev/null
+++ b/skyvern/forge/sdk/services/sftp_service.py
@@ -0,0 +1,81 @@
+import asyncio
+import posixpath
+from pathlib import Path
+from typing import Any
+
+import asyncssh
+import structlog
+
+from skyvern.config import settings
+from skyvern.utils.url_validators import resolve_fetch_host_ips
+
+LOG = structlog.get_logger()
+
+
+def build_remote_target(remote_path: str | None, filename: str) -> str:
+ if remote_path:
+ return posixpath.join(remote_path, filename)
+ return filename
+
+
+async def upload_file(
+ *,
+ file_path: str,
+ host: str,
+ port: int,
+ username: str,
+ remote_path: str | None = None,
+ password: str | None = None,
+ private_key: str | None = None,
+ private_key_passphrase: str | None = None,
+ host_key: str | None = None,
+ connect_timeout: int = 30,
+) -> str:
+ connect_host = host
+ host_key_alias: str | None = None
+ if not settings.ALLOW_SFTP_INTERNAL_HOSTS:
+ resolved_ips = await asyncio.to_thread(resolve_fetch_host_ips, host)
+ connect_host = resolved_ips[0]
+ # Connect directly to the validated address to prevent a second DNS
+ # lookup from rebinding the hostname to an internal target. Keep the
+ # configured hostname as the identity used for host-key validation.
+ host_key_alias = host
+
+ connect_kwargs: dict[str, Any] = {
+ "host": connect_host,
+ "port": port,
+ "username": username,
+ "connect_timeout": connect_timeout,
+ # Authenticate only with the credentials configured on the block, never the
+ # worker's ambient SSH identity (ssh config, agent, default keys, or GSSAPI).
+ "config": None,
+ "agent_path": None,
+ "gss_host": None,
+ "client_keys": None,
+ }
+ if host_key_alias:
+ connect_kwargs["host_key_alias"] = host_key_alias
+
+ if host_key:
+ entry = f"[{host}]:{port}" if port != 22 else host
+ known_hosts: bytes | None = f"{entry} {host_key}\n".encode()
+ else:
+ known_hosts = None
+ LOG.warning("SFTP host key verification disabled; no host_key provided", host=host, port=port)
+ connect_kwargs["known_hosts"] = known_hosts
+
+ if private_key:
+ connect_kwargs["client_keys"] = [
+ asyncssh.import_private_key(private_key, passphrase=private_key_passphrase or None)
+ ]
+ if password:
+ connect_kwargs["password"] = password
+
+ async with asyncssh.connect(**connect_kwargs) as conn:
+ async with conn.start_sftp_client() as sftp:
+ filename = Path(file_path).name
+ if remote_path:
+ await sftp.makedirs(remote_path, exist_ok=True)
+ remote_target = build_remote_target(remote_path, filename)
+ await sftp.put(file_path, remote_target)
+ return remote_target
diff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.py
index 21bfc64de..740a581e0 100644
--- a/skyvern/forge/sdk/workflow/models/block.py
+++ b/skyvern/forge/sdk/workflow/models/block.py
@@ -108,7 +108,7 @@ from skyvern.forge.sdk.models import Step, StepStatus
from skyvern.forge.sdk.schemas.files import FileInfo
from skyvern.forge.sdk.schemas.task_v2 import TaskV2Status
from skyvern.forge.sdk.schemas.tasks import Task, TaskOutput, TaskStatus
-from skyvern.forge.sdk.services import google_drive_service, google_oauth_service
+from skyvern.forge.sdk.services import google_drive_service, google_oauth_service, sftp_service
from skyvern.forge.sdk.services.bitwarden import BitwardenConstants
from skyvern.forge.sdk.services.credentials import AzureVaultConstants, OnePasswordConstants, generate_totp_code
from skyvern.forge.sdk.settings_manager import SettingsManager
@@ -5580,6 +5580,14 @@ class FileUploadBlock(Block):
azure_blob_container_name: str | None = None
google_credential_id: str | None = None
google_drive_folder_id: str | None = None
+ sftp_host: str | None = None
+ sftp_port: int | None = None
+ sftp_username: str | None = None
+ sftp_password: str | None = None
+ sftp_private_key: str | None = None
+ sftp_private_key_passphrase: str | None = None
+ sftp_remote_path: str | None = None
+ sftp_host_key: str | None = None
path: str | None = None
continue_on_empty: bool = Field(
default=False,
@@ -5624,6 +5632,27 @@ class FileUploadBlock(Block):
if self.google_drive_folder_id and workflow_run_context.has_parameter(self.google_drive_folder_id):
parameters.append(workflow_run_context.get_parameter(self.google_drive_folder_id))
+ if self.sftp_host and workflow_run_context.has_parameter(self.sftp_host):
+ parameters.append(workflow_run_context.get_parameter(self.sftp_host))
+
+ if self.sftp_username and workflow_run_context.has_parameter(self.sftp_username):
+ parameters.append(workflow_run_context.get_parameter(self.sftp_username))
+
+ if self.sftp_password and workflow_run_context.has_parameter(self.sftp_password):
+ parameters.append(workflow_run_context.get_parameter(self.sftp_password))
+
+ if self.sftp_private_key and workflow_run_context.has_parameter(self.sftp_private_key):
+ parameters.append(workflow_run_context.get_parameter(self.sftp_private_key))
+
+ if self.sftp_private_key_passphrase and workflow_run_context.has_parameter(self.sftp_private_key_passphrase):
+ parameters.append(workflow_run_context.get_parameter(self.sftp_private_key_passphrase))
+
+ if self.sftp_remote_path and workflow_run_context.has_parameter(self.sftp_remote_path):
+ parameters.append(workflow_run_context.get_parameter(self.sftp_remote_path))
+
+ if self.sftp_host_key and workflow_run_context.has_parameter(self.sftp_host_key):
+ parameters.append(workflow_run_context.get_parameter(self.sftp_host_key))
+
return parameters
def format_potential_template_parameters(self, workflow_run_context: WorkflowRunContext) -> None:
@@ -5662,6 +5691,34 @@ class FileUploadBlock(Block):
self.google_drive_folder_id = self.format_block_parameter_template_from_workflow_run_context(
self.google_drive_folder_id, workflow_run_context
)
+ if self.sftp_host:
+ self.sftp_host = self.format_block_parameter_template_from_workflow_run_context(
+ self.sftp_host, workflow_run_context
+ )
+ if self.sftp_username:
+ self.sftp_username = self.format_block_parameter_template_from_workflow_run_context(
+ self.sftp_username, workflow_run_context
+ )
+ if self.sftp_password:
+ self.sftp_password = self.format_block_parameter_template_from_workflow_run_context(
+ self.sftp_password, workflow_run_context
+ )
+ if self.sftp_private_key:
+ self.sftp_private_key = self.format_block_parameter_template_from_workflow_run_context(
+ self.sftp_private_key, workflow_run_context
+ )
+ if self.sftp_private_key_passphrase:
+ self.sftp_private_key_passphrase = self.format_block_parameter_template_from_workflow_run_context(
+ self.sftp_private_key_passphrase, workflow_run_context
+ )
+ if self.sftp_remote_path:
+ self.sftp_remote_path = self.format_block_parameter_template_from_workflow_run_context(
+ self.sftp_remote_path, workflow_run_context
+ )
+ if self.sftp_host_key:
+ self.sftp_host_key = self.format_block_parameter_template_from_workflow_run_context(
+ self.sftp_host_key, workflow_run_context
+ )
def _get_s3_uri(self, workflow_run_id: str, path: str) -> str:
folder_path = self.path or f"{workflow_run_id}"
@@ -5741,6 +5798,36 @@ class FileUploadBlock(Block):
google_drive_folder_id=folder_id,
)
+ def _build_sftp_destination(
+ self,
+ *,
+ file_path: str,
+ host: str,
+ port: int,
+ username: str,
+ password: str | None,
+ private_key: str | None,
+ private_key_passphrase: str | None,
+ remote_path: str | None,
+ host_key: str | None,
+ ) -> FileUploadDestination:
+ filename = Path(file_path).name
+ remote_target = sftp_service.build_remote_target(remote_path, filename)
+ remote_uri = f"sftp://{host}:{port}/{remote_target.lstrip('/')}"
+ return FileUploadDestination(
+ storage_type=FileStorageType.SFTP,
+ customer_uri=remote_uri,
+ sdk_uri=remote_uri,
+ sftp_host=host,
+ sftp_port=port,
+ sftp_username=username,
+ sftp_password=password,
+ sftp_private_key=private_key,
+ sftp_private_key_passphrase=private_key_passphrase,
+ sftp_remote_path=remote_path,
+ sftp_host_key=host_key,
+ )
+
@staticmethod
def _candidate_download_signal_run_ids(
*,
@@ -5961,6 +6048,13 @@ class FileUploadBlock(Block):
missing_parameters.append("google_credential_id")
if not self.google_drive_folder_id:
missing_parameters.append("google_drive_folder_id")
+ elif self.storage_type == FileStorageType.SFTP:
+ if not self.sftp_host:
+ missing_parameters.append("sftp_host")
+ if not self.sftp_username:
+ missing_parameters.append("sftp_username")
+ if not self.sftp_password and not self.sftp_private_key:
+ missing_parameters.append("sftp_password or sftp_private_key")
else:
return await self.build_block_result(
success=False,
@@ -6003,7 +6097,7 @@ class FileUploadBlock(Block):
files_to_upload = []
max_file_count = (
MAX_UPLOAD_FILE_COUNT
- if self.storage_type in {FileStorageType.S3, FileStorageType.GOOGLE_DRIVE}
+ if self.storage_type in {FileStorageType.S3, FileStorageType.GOOGLE_DRIVE, FileStorageType.SFTP}
else AZURE_BLOB_STORAGE_MAX_UPLOAD_FILE_COUNT
)
files_to_upload = self._get_files_to_upload_from_download_dir(
@@ -6170,6 +6264,42 @@ class FileUploadBlock(Block):
)
uploaded_uris.append(customer_uri)
LOG.info("FileUploadBlock File(s) uploaded to Google Drive", file_path=self.path)
+ elif self.storage_type == FileStorageType.SFTP:
+ actual_sftp_username = (
+ workflow_run_context.get_original_secret_value_or_none(self.sftp_username) or self.sftp_username
+ )
+ actual_sftp_password = (
+ workflow_run_context.get_original_secret_value_or_none(self.sftp_password) or self.sftp_password
+ )
+ actual_sftp_private_key = (
+ workflow_run_context.get_original_secret_value_or_none(self.sftp_private_key)
+ or self.sftp_private_key
+ )
+ actual_sftp_passphrase = (
+ workflow_run_context.get_original_secret_value_or_none(self.sftp_private_key_passphrase)
+ or self.sftp_private_key_passphrase
+ )
+ sftp_port = 22 if self.sftp_port is None else self.sftp_port
+ for file_path in files_to_upload:
+ destination = self._build_sftp_destination(
+ file_path=file_path,
+ host=self.sftp_host or "",
+ port=sftp_port,
+ username=actual_sftp_username or "",
+ password=actual_sftp_password,
+ private_key=actual_sftp_private_key,
+ private_key_passphrase=actual_sftp_passphrase,
+ remote_path=self.sftp_remote_path,
+ host_key=self.sftp_host_key,
+ )
+ customer_uri = await app.AGENT_FUNCTION.upload_file_to_customer_storage(
+ file_path=file_path,
+ destination=destination,
+ organization_id=organization_id,
+ run_id=workflow_run_id,
+ )
+ uploaded_uris.append(customer_uri)
+ LOG.info("FileUploadBlock File(s) uploaded to SFTP", file_path=self.path)
else:
# This case should ideally be caught by the initial validation
raise ValueError(f"Unsupported storage type: {self.storage_type}")
diff --git a/skyvern/forge/sdk/workflow/workflow_definition_converter.py b/skyvern/forge/sdk/workflow/workflow_definition_converter.py
index 99165cecf..97da39454 100644
--- a/skyvern/forge/sdk/workflow/workflow_definition_converter.py
+++ b/skyvern/forge/sdk/workflow/workflow_definition_converter.py
@@ -636,6 +636,14 @@ def block_yaml_to_block(
azure_blob_container_name=block_yaml.azure_blob_container_name,
google_credential_id=block_yaml.google_credential_id,
google_drive_folder_id=block_yaml.google_drive_folder_id,
+ sftp_host=block_yaml.sftp_host,
+ sftp_port=block_yaml.sftp_port,
+ sftp_username=block_yaml.sftp_username,
+ sftp_password=block_yaml.sftp_password,
+ sftp_private_key=block_yaml.sftp_private_key,
+ sftp_private_key_passphrase=block_yaml.sftp_private_key_passphrase,
+ sftp_remote_path=block_yaml.sftp_remote_path,
+ sftp_host_key=block_yaml.sftp_host_key,
path=block_yaml.path,
)
elif block_yaml.block_type == BlockType.SEND_EMAIL:
diff --git a/skyvern/schemas/workflows.py b/skyvern/schemas/workflows.py
index 043c1b458..b52bf640c 100644
--- a/skyvern/schemas/workflows.py
+++ b/skyvern/schemas/workflows.py
@@ -506,6 +506,7 @@ class FileStorageType(StrEnum):
S3 = "s3"
AZURE = "azure"
GOOGLE_DRIVE = "google_drive"
+ SFTP = "sftp"
class FileUploadDestination(BaseModel):
@@ -533,6 +534,14 @@ class FileUploadDestination(BaseModel):
google_access_token: str | None = None
google_drive_folder_id: str | None = None
+ sftp_host: str | None = None
+ sftp_port: int | None = None
+ sftp_username: str | None = None
+ sftp_password: str | None = None
+ sftp_private_key: str | None = None
+ sftp_private_key_passphrase: str | None = None
+ sftp_remote_path: str | None = None
+ sftp_host_key: str | None = None
class ParameterYAML(BaseModel, abc.ABC):
@@ -916,6 +925,14 @@ class FileUploadBlockYAML(BlockYAML):
azure_folder_path: str | None = None
google_credential_id: str | None = None
google_drive_folder_id: str | None = None
+ sftp_host: str | None = None
+ sftp_port: int | None = None
+ sftp_username: str | None = None
+ sftp_password: str | None = None
+ sftp_private_key: str | None = None
+ sftp_private_key_passphrase: str | None = None
+ sftp_remote_path: str | None = None
+ sftp_host_key: str | None = None
path: str | None = None
diff --git a/skyvern/services/script_service.py b/skyvern/services/script_service.py
index c18c7e533..485b1bbce 100644
--- a/skyvern/services/script_service.py
+++ b/skyvern/services/script_service.py
@@ -2872,6 +2872,14 @@ async def upload_file(
azure_blob_container_name: str | None = None,
google_credential_id: str | None = None,
google_drive_folder_id: str | None = None,
+ sftp_host: str | None = None,
+ sftp_port: int | None = None,
+ sftp_username: str | None = None,
+ sftp_password: str | None = None,
+ sftp_private_key: str | None = None,
+ sftp_private_key_passphrase: str | None = None,
+ sftp_remote_path: str | None = None,
+ sftp_host_key: str | None = None,
path: str | None = None,
) -> None:
block_validation_output = await _validate_and_get_output_parameter(label, parameters)
@@ -2893,6 +2901,20 @@ async def upload_file(
google_credential_id = _render_template_with_label(google_credential_id, label)
if google_drive_folder_id:
google_drive_folder_id = _render_template_with_label(google_drive_folder_id, label)
+ if sftp_host:
+ sftp_host = _render_template_with_label(sftp_host, label)
+ if sftp_username:
+ sftp_username = _render_template_with_label(sftp_username, label)
+ if sftp_password:
+ sftp_password = _render_template_with_label(sftp_password, label)
+ if sftp_private_key:
+ sftp_private_key = _render_template_with_label(sftp_private_key, label)
+ if sftp_private_key_passphrase:
+ sftp_private_key_passphrase = _render_template_with_label(sftp_private_key_passphrase, label)
+ if sftp_remote_path:
+ sftp_remote_path = _render_template_with_label(sftp_remote_path, label)
+ if sftp_host_key:
+ sftp_host_key = _render_template_with_label(sftp_host_key, label)
if path:
path = _render_template_with_label(path, label)
file_upload_block = FileUploadBlock(
@@ -2909,6 +2931,14 @@ async def upload_file(
azure_blob_container_name=azure_blob_container_name,
google_credential_id=google_credential_id,
google_drive_folder_id=google_drive_folder_id,
+ sftp_host=sftp_host,
+ sftp_port=sftp_port,
+ sftp_username=sftp_username,
+ sftp_password=sftp_password,
+ sftp_private_key=sftp_private_key,
+ sftp_private_key_passphrase=sftp_private_key_passphrase,
+ sftp_remote_path=sftp_remote_path,
+ sftp_host_key=sftp_host_key,
path=path,
)
await file_upload_block.execute_safe(
diff --git a/tests/unit/test_sftp_upload.py b/tests/unit/test_sftp_upload.py
new file mode 100644
index 000000000..7de6f7ba5
--- /dev/null
+++ b/tests/unit/test_sftp_upload.py
@@ -0,0 +1,297 @@
+from unittest.mock import AsyncMock, MagicMock, patch
+
+import libcst as cst
+import pytest
+
+from skyvern.core.script_generations.generate_script import _build_file_upload_statement
+from skyvern.exceptions import BlockedHost
+from skyvern.forge.agent_functions import AgentFunction
+from skyvern.forge.sdk.services import sftp_service
+from skyvern.schemas.workflows import FileStorageType, FileUploadDestination
+
+
+def _acm(enter_value):
+ cm = MagicMock()
+ cm.__aenter__ = AsyncMock(return_value=enter_value)
+ cm.__aexit__ = AsyncMock(return_value=False)
+ return cm
+
+
+def _write_file(tmp_path, name: str = "f.csv") -> str:
+ file_path = tmp_path / name
+ file_path.write_text("data")
+ return str(file_path)
+
+
+def _mock_sftp_asyncssh(mock_asyncssh):
+ sftp = AsyncMock()
+ conn = MagicMock()
+ conn.start_sftp_client = MagicMock(return_value=_acm(sftp))
+ mock_asyncssh.connect = MagicMock(return_value=_acm(conn))
+ mock_asyncssh.import_private_key = MagicMock(return_value="KEYOBJ")
+ return sftp
+
+
+def _sftp_destination(**overrides) -> FileUploadDestination:
+ fields = {
+ "storage_type": FileStorageType.SFTP,
+ "customer_uri": "sftp://h:22/incoming/f.csv",
+ "sdk_uri": "sftp://h:22/incoming/f.csv",
+ "sftp_host": "h",
+ "sftp_port": 22,
+ "sftp_username": "u",
+ "sftp_password": "pw",
+ "sftp_remote_path": "/incoming",
+ }
+ fields.update(overrides)
+ return FileUploadDestination(**fields)
+
+
+async def test_sftp_service_upload_file_uses_password_auth_and_remote_path(tmp_path):
+ file_path = _write_file(tmp_path)
+
+ with (
+ patch("skyvern.forge.sdk.services.sftp_service.asyncssh") as mock_asyncssh,
+ patch("skyvern.forge.sdk.services.sftp_service.resolve_fetch_host_ips", return_value=("1.2.3.4",)),
+ ):
+ sftp = _mock_sftp_asyncssh(mock_asyncssh)
+
+ result = await sftp_service.upload_file(
+ file_path=file_path,
+ host="h",
+ port=22,
+ username="u",
+ password="pw",
+ remote_path="/incoming",
+ )
+
+ mock_asyncssh.connect.assert_called_once()
+ connect_kwargs = mock_asyncssh.connect.call_args.kwargs
+ # Connect to the already-validated address so DNS rebinding cannot change
+ # the destination between SSRF validation and socket creation.
+ assert connect_kwargs["host"] == "1.2.3.4"
+ assert connect_kwargs["host_key_alias"] == "h"
+ assert connect_kwargs["port"] == 22
+ assert connect_kwargs["username"] == "u"
+ assert connect_kwargs["password"] == "pw"
+ assert connect_kwargs["known_hosts"] is None
+ assert connect_kwargs["config"] is None
+ assert connect_kwargs["agent_path"] is None
+ assert connect_kwargs["gss_host"] is None
+ assert connect_kwargs["client_keys"] is None
+ sftp.makedirs.assert_awaited_once_with("/incoming", exist_ok=True)
+ sftp.put.assert_awaited_once_with(file_path, "/incoming/f.csv")
+ assert result == "/incoming/f.csv"
+ mock_asyncssh.import_private_key.assert_not_called()
+
+
+async def test_sftp_service_upload_file_uses_private_key_auth_without_remote_path(tmp_path):
+ file_path = _write_file(tmp_path)
+
+ with (
+ patch("skyvern.forge.sdk.services.sftp_service.asyncssh") as mock_asyncssh,
+ patch("skyvern.forge.sdk.services.sftp_service.resolve_fetch_host_ips", return_value=("1.2.3.4",)),
+ ):
+ sftp = _mock_sftp_asyncssh(mock_asyncssh)
+
+ result = await sftp_service.upload_file(
+ file_path=file_path,
+ host="h",
+ port=22,
+ username="u",
+ private_key="PEM",
+ private_key_passphrase="secret",
+ remote_path=None,
+ )
+
+ mock_asyncssh.import_private_key.assert_called_once_with("PEM", passphrase="secret")
+ connect_kwargs = mock_asyncssh.connect.call_args.kwargs
+ assert connect_kwargs["client_keys"] == ["KEYOBJ"]
+ assert connect_kwargs["config"] is None
+ assert connect_kwargs["agent_path"] is None
+ assert connect_kwargs["gss_host"] is None
+ assert "password" not in connect_kwargs
+ sftp.makedirs.assert_not_awaited()
+ sftp.put.assert_awaited_once_with(file_path, "f.csv")
+ assert result == "f.csv"
+
+
+async def test_sftp_service_upload_file_pins_host_key_on_non_default_port(tmp_path):
+ file_path = _write_file(tmp_path)
+
+ with (
+ patch("skyvern.forge.sdk.services.sftp_service.asyncssh") as mock_asyncssh,
+ patch("skyvern.forge.sdk.services.sftp_service.resolve_fetch_host_ips", return_value=("1.2.3.4",)),
+ ):
+ _mock_sftp_asyncssh(mock_asyncssh)
+
+ await sftp_service.upload_file(
+ file_path=file_path,
+ host="h",
+ port=2222,
+ username="u",
+ password="pw",
+ host_key="ssh-ed25519 AAAA",
+ )
+
+ assert mock_asyncssh.connect.call_args.kwargs["known_hosts"] == b"[h]:2222 ssh-ed25519 AAAA\n"
+
+
+async def test_sftp_service_upload_file_pins_host_key_on_default_port(tmp_path):
+ file_path = _write_file(tmp_path)
+
+ with (
+ patch("skyvern.forge.sdk.services.sftp_service.asyncssh") as mock_asyncssh,
+ patch("skyvern.forge.sdk.services.sftp_service.resolve_fetch_host_ips", return_value=("1.2.3.4",)),
+ ):
+ _mock_sftp_asyncssh(mock_asyncssh)
+
+ await sftp_service.upload_file(
+ file_path=file_path,
+ host="h",
+ port=22,
+ username="u",
+ password="pw",
+ host_key="ssh-ed25519 AAAA",
+ )
+
+ assert mock_asyncssh.connect.call_args.kwargs["known_hosts"] == b"h ssh-ed25519 AAAA\n"
+
+
+async def test_sftp_service_upload_file_blocks_internal_host(tmp_path):
+ file_path = _write_file(tmp_path)
+
+ with (
+ patch("skyvern.forge.sdk.services.sftp_service.asyncssh") as mock_asyncssh,
+ patch(
+ "skyvern.forge.sdk.services.sftp_service.resolve_fetch_host_ips",
+ side_effect=BlockedHost(host="169.254.169.254"),
+ ),
+ pytest.raises(BlockedHost),
+ ):
+ await sftp_service.upload_file(
+ file_path=file_path,
+ host="169.254.169.254",
+ port=22,
+ username="u",
+ password="pw",
+ )
+
+ mock_asyncssh.connect.assert_not_called()
+
+
+async def test_sftp_service_upload_file_skips_guard_when_internal_hosts_allowed(tmp_path, monkeypatch):
+ file_path = _write_file(tmp_path)
+ monkeypatch.setattr(sftp_service.settings, "ALLOW_SFTP_INTERNAL_HOSTS", True)
+
+ with (
+ patch("skyvern.forge.sdk.services.sftp_service.asyncssh") as mock_asyncssh,
+ patch("skyvern.forge.sdk.services.sftp_service.resolve_fetch_host_ips") as mock_resolve_fetch_host_ips,
+ ):
+ _mock_sftp_asyncssh(mock_asyncssh)
+
+ await sftp_service.upload_file(
+ file_path=file_path,
+ host="h",
+ port=22,
+ username="u",
+ password="pw",
+ )
+
+ mock_resolve_fetch_host_ips.assert_not_called()
+ mock_asyncssh.connect.assert_called_once()
+
+
+async def test_agent_function_upload_file_to_customer_storage_sftp_happy_path(tmp_path):
+ file_path = _write_file(tmp_path)
+ destination = _sftp_destination()
+
+ with patch("skyvern.forge.agent_functions.sftp_service.upload_file", new_callable=AsyncMock) as mock_upload:
+ result = await AgentFunction().upload_file_to_customer_storage(file_path, destination)
+
+ assert result == destination.customer_uri
+ mock_upload.assert_awaited_once_with(
+ file_path=file_path,
+ host="h",
+ port=22,
+ username="u",
+ remote_path="/incoming",
+ password="pw",
+ private_key=None,
+ private_key_passphrase=None,
+ host_key=None,
+ )
+
+
+async def test_agent_function_upload_file_to_customer_storage_sftp_requires_host(tmp_path):
+ file_path = _write_file(tmp_path)
+ destination = _sftp_destination(sftp_host=None, sftp_username="u", sftp_password="pw")
+
+ with pytest.raises(ValueError):
+ await AgentFunction().upload_file_to_customer_storage(file_path, destination)
+
+
+async def test_agent_function_upload_file_to_customer_storage_sftp_requires_auth(tmp_path):
+ file_path = _write_file(tmp_path)
+ destination = _sftp_destination(sftp_host="h", sftp_username="u", sftp_password=None, sftp_private_key=None)
+
+ with pytest.raises(ValueError):
+ await AgentFunction().upload_file_to_customer_storage(file_path, destination)
+
+
+def test_generated_script_emits_sftp_fields():
+ block = {
+ "label": "sftp_upload",
+ "parameters": [],
+ "storage_type": "sftp",
+ "sftp_host": "h",
+ "sftp_port": 2222,
+ "sftp_username": "u",
+ "sftp_password": "pw",
+ "sftp_private_key": "PEM",
+ "sftp_private_key_passphrase": "secret",
+ "sftp_remote_path": "/incoming",
+ "sftp_host_key": "ssh-ed25519 AAAA",
+ }
+
+ compact = cst.Module(body=[_build_file_upload_statement(block)]).code.replace(" ", "").replace("\n", "")
+
+ assert "storage_type='sftp'" in compact
+ for field in (
+ "sftp_host",
+ "sftp_port",
+ "sftp_username",
+ "sftp_password",
+ "sftp_private_key",
+ "sftp_private_key_passphrase",
+ "sftp_remote_path",
+ "sftp_host_key",
+ ):
+ assert f"{field}=" in compact
+ assert "sftp_port=2222" in compact
+
+
+def test_generated_script_omits_absent_sftp_fields():
+ block = {
+ "label": "sftp_upload",
+ "parameters": [],
+ "storage_type": "sftp",
+ "sftp_host": "h",
+ "sftp_username": "u",
+ "sftp_password": "pw",
+ }
+
+ compact = cst.Module(body=[_build_file_upload_statement(block)]).code.replace(" ", "").replace("\n", "")
+
+ assert "sftp_host=" in compact
+ assert "sftp_private_key=" not in compact
+ assert "s3_bucket=" not in compact
diff --git a/uv.lock b/uv.lock
index fc704f6bf..f4438ac97 100644
--- a/uv.lock
+++ b/uv.lock
@@ -453,6 +453,19 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/91/66/b25ccb84a246b470eb943b0107c07edcae51804912b824054b3413995a10/asyncpg-0.31.0-cp313-cp313-win_amd64.whl", hash = "sha256:dc5f2fa9916f292e5c5c8b2ac2813763bcd7f58e130055b4ad8a0531314201ab", size = 596569, upload-time = "2025-11-24T23:26:16.189Z" },
]
+[[package]]
+name = "asyncssh"
+version = "2.24.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "cryptography" },
+ { name = "typing-extensions" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/dd/7f/2d79247bacc562104f312d27efe541673aa177feac89de291bd61bca52be/asyncssh-2.24.0.tar.gz", hash = "sha256:4064c590e59ce2e8d82a2f66d35f3120d765828b4df5e3dbfb07b4a8c24686c9", size = 550148, upload-time = "2026-06-27T20:34:44.755Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/3e/29/908ce0ca5e8cae76662e354a0f08df552d6d221844748b9e5ca06051cc44/asyncssh-2.24.0-py3-none-any.whl", hash = "sha256:9abd46300adcb6d4b73269b34c53cd0d17a138b9a22b5b38008ce7d5808734b7", size = 381237, upload-time = "2026-06-27T20:34:43.198Z" },
+]
+
[[package]]
name = "attrs"
version = "26.1.0"
@@ -5807,6 +5820,7 @@ local = [
{ name = "alembic" },
{ name = "anthropic" },
{ name = "asyncache" },
+ { name = "asyncssh" },
{ name = "authlib" },
{ name = "azure-identity" },
{ name = "azure-keyvault-secrets" },
@@ -5872,6 +5886,7 @@ server = [
{ name = "anthropic" },
{ name = "asyncache" },
{ name = "asyncpg" },
+ { name = "asyncssh" },
{ name = "authlib" },
{ name = "azure-identity" },
{ name = "azure-keyvault-secrets" },
@@ -6009,6 +6024,8 @@ requires-dist = [
{ name = "asyncache", marker = "extra == 'local'", specifier = ">=0.3.1,<0.4" },
{ name = "asyncache", marker = "extra == 'server'", specifier = ">=0.3.1,<0.4" },
{ name = "asyncpg", marker = "extra == 'server'", specifier = ">=0.30.0,<0.32" },
+ { name = "asyncssh", marker = "extra == 'local'", specifier = ">=2.14.2,<3" },
+ { name = "asyncssh", marker = "extra == 'server'", specifier = ">=2.14.2,<3" },
{ name = "authlib", marker = "extra == 'local'", specifier = ">=1.7.1" },
{ name = "authlib", marker = "extra == 'server'", specifier = ">=1.7.1" },
{ name = "azure-identity", marker = "extra == 'local'", specifier = ">=1.24.0,<2" },