Skip to content

SFTP and File Copy

Knot provides two styles of file operation: the interactive knot sftp shell and script-friendly batch commands. knot cp uses Docker-style alias:/path remote paths for copying between the local machine and one remote server.

Interactive SFTP

sh
knot sftp [alias] [remote_path]
ArgumentRequiredDescription
[alias]YesServer alias.
[remote_path]NoInitial remote directory.

Examples:

sh
knot sftp web-prod
knot sftp web-prod /var/www

The interactive shell supports command and path completion.

SFTP Shell Commands

CommandUsageDescription
helphelp or ?Show help.
exitexit, quit, or byeExit the SFTP shell.
lsls [path]List remote directory contents.
pwdpwdPrint the current remote directory.
cdcd <path>Change remote directory.
getget <remote_path> [local_path]Download a file or directory.
putput <local_path> [remote_path]Upload a file or directory.
mgetmget <remote_pattern> [local_dir]Download files matching a wildcard.
mputmput <local_pattern> [remote_dir]Upload files matching a wildcard.
rmrm <path>Remove a remote file.
mkdirmkdir <path>Create a remote directory.
rmdirrmdir <path>Remove a remote directory.

Example:

text
sftp:/var/www> ls
sftp:/var/www> put ./dist/app.tar.gz /tmp/app.tar.gz
sftp:/var/www> get release.tar.gz ~/Downloads/

Batch SFTP Commands

These commands do not enter the interactive shell and are suitable for scripts:

CommandUsageDescription
knot sftp lsknot sftp ls alias:/pathList a remote directory.
knot sftp statknot sftp stat alias:/pathShow remote file or directory metadata.
knot sftp rmknot sftp rm alias:/pathRemove a remote file.
knot sftp mkdirknot sftp mkdir alias:/pathCreate a remote directory, including missing parents.
knot sftp rmdirknot sftp rmdir alias:/pathRemove a remote directory.
knot sftp mvknot sftp mv alias:/old alias:/newRename a remote file or directory. Source and destination must use the same alias.

Examples:

sh
knot sftp ls web-prod:/var/www
knot sftp stat web-prod:/var/www/index.html
knot sftp mv web-prod:/tmp/a web-prod:/tmp/b

knot cp

sh
knot cp [SRC] [DEST] [flags]
ArgumentRequiredDescription
[SRC]YesLocal path or remote path in alias:/path form.
[DEST]YesLocal path or remote path in alias:/path form. Remote-to-remote copy is not supported.
FlagTypeDefaultDescription
-r, --recursivebooltrueCopy directories recursively.
-f, --forceboolfalseOverwrite existing files.

Examples:

sh
knot cp ./dist/. web-prod:/var/www/html/
knot cp web-prod:/var/log/nginx/access.log ./

When the source directory ends with /., Knot copies the directory contents instead of the directory itself.