# Command line

CrushClient's engine also works without the window: type commands, run a script, or pass the commands on one line. It is the same engine, with the same protocols.

For one copy, move or delete in a single line, see [Single command](Single-Command.md).

## Starting it

The engine is in `CrushTunnel.jar`. Every CrushMFT server has the jar in its `WebInterface` folder, and the desktop app has it in its program folder. With Java:

```
java -jar CrushTunnel.jar
java -jar CrushTunnel.jar https://demo:demo@crushftp.com/demo/
java -jar CrushTunnel.jar https://demo:demo@crushftp.com/demo/ file://c:/temp/
java -jar CrushTunnel.jar script my_commands.txt
java -jar CrushTunnel.jar inline_script "connect https://demo:demo@crushftp.com/demo/;put file.txt;wait;quit;"
```

| Form | What it does |
|---|---|
| no arguments | starts the prompt; type commands |
| one URL | connects the remote side, then the prompt |
| two URLs | connects the remote side and the local side |
| `script <file>` | reads commands from the file, one per line, as if you typed them |
| `inline_script "<commands>"` | the commands in one argument, separated by `;` |

**End every script with `wait` and `quit`.** Without `quit` the client waits for more input for ever.

## The basics

- **URLs** look like `https://user:pass@server.example.com:443/path/`. The URL must end with a slash. User and password are optional; you are asked for them when they are missing.
- **Two sides.** A command acts on the remote side. With a leading `l` it acts on the local side: `ls` lists the remote folder, `lls` the local one; `cd` and `lcd` change folders. The "local" side does not have to be this computer: think of it as the left side. Both sides can be servers, and files then stream through CrushClient.
- **Only the transfer commands** (`put`, `get`, `diffput`, `diffget`) have no `l` form.
- **Paths with spaces** must be quoted: `put "some file.txt" "/some folder/my file.txt"`. A backslash before a quote escapes it.
- **Background:** a command that ends with `&` runs in the background: `put file.txt remote.txt&`.
- **Exit code:** a script that fails ends with a code other than 0.

## Connecting

| Command | Does |
|---|---|
| `connect <url>`, `lconnect <url>` | connects a side |
| `disconnect`, `ldisconnect` | disconnects a side, so you can connect it somewhere else |
| `pasv`, `lpasv` | switches FTP passive mode on or off |
| `quote <anything>`, `lquote <anything>` | sends a raw command to an FTP server |
| `cipher list` | lists the ciphers available for TLS (by making a test connection to www.crushftp.com) |
| `cipher set <cipher>` | uses that cipher for TLS connections |
| `cipher get` | shows the cipher of the last connection |
| `cipher trust` | trusts every certificate, expired or not. For testing only, never for real use. |
| `timeout <seconds>` | the timeout for single transfers over FTP, HTTP(S) and SFTP |

## Looking around

| Command | Does |
|---|---|
| `list`, `dir`, `ls` and `llist`, `ldir`, `lls` | a directory listing in the Unix style |
| `cd`, `cwd` and `lcd`, `lcwd` | change the folder |
| `pwd`, `lpwd` | print the folder |
| `stat <path>`, `lstat <path>` | details of one item |
| `diff <local path> <remote path>` | lists the parts in which two files differ |

## Transfers

| Command | Does |
|---|---|
| `get <remote path> [local path]` | downloads a file or folder. Patterns work: `get /in/*.TXT`, `get /in/ABC???_*.TXT`. There is no `mget`: `get` takes one or many. |
| `reget <remote path> [local path]` | resumes a download from the size of the local file |
| `put <local path> [remote path]` | uploads a file or folder. Patterns work: `put /out/*.XML`. There is no `mput`. |
| `reput <local path> [remote path]` | resumes an upload from the size of the remote file |
| `appe <local path> [remote path]` | appends to the remote file |
| `move <local path> [remote path]` | uploads, then deletes the source |
| `diffput`, `diffget` | like `put` and `get`, but first works out which parts of the files differ and transfers only those. The remote side must be a CrushMFT server. |
| `diffdir` | shows what `putdel` would do, without doing it: the deletes and copies that would make the remote side match the local side |
| `putdel <local path> [remote path]` | a one-way sync: copies and replaces, and **deletes on the destination whatever is not on the source**. One typo erases the target you named. Run `diffdir` first. |
| `wait`, `lwait` | waits for the running transfers to finish, printing progress now and then |
| `info [all/clear]`, `linfo [all/clear]` | prints the state of the running transfers once |
| `abor` | stops all running transfers |
| `local_echo` | makes an inline script show transfer progress |

> [!CAUTION]
> `putsync <local path> [remote path]` is an experimental two-way sync and is flawed. It decides from modified dates and its own last run time which side is newer and what was deleted, and deletes on both sides. A file copied in with an older date can be taken for deleted and removed from both sides. Do not use it unless you understand this fully; you can lose data. For two-way synchronization use [CrushSync](../CrushSync/Main.md).

## Changing things

| Command | Does |
|---|---|
| `mkd <path>`, `lmkd <path>` | makes a folder |
| `rename <from> <to>`, `mv <from> <to>` and `lrename`, `lmv` | renames; both names are needed |
| `del <path>`, `ldel <path>` | deletes |
| `mdtm <path> yyyyMMddHHmmss`, `lmdtm …` | sets the modified date |

## Settings

`set <name> <value>` changes how the client works, or stores a value for later use:

| Name | Default | Meaning |
|---|---|---|
| `download_threads` | 0 (no limit) | files downloaded at once |
| `upload_threads` | 0 (no limit) | files uploaded at once |
| `skip_modified_and_size` | true | skip a file when size and date match |
| `skip_modified` | false | skip on the date alone (ignored while the one above is true) |
| `skip_size` | false | skip on the size alone (ignored while either above is true) |
| `keep_date` | true | keep the modified date on transferred files |
| `multithreaded` | true | several files at once |

`config <name> <value>` and `lconfig <name> <value>` set an option of one connection, before `connect`. The names are the same ones a CrushMFT server uses for a remote VFS item; the easiest way to find one is to set the option in the window, save it in a bookmark, and look at the bookmark. Examples are on the [PGP](PGP.md) page.

## Queues, delays and limits

| Command | Does |
|---|---|
| `queue <id> add <command>` | adds a command to a named list |
| `queue <id> run` | runs the list |
| `queue <id> reset` | empties it |
| `delay <milliseconds>` | waits |
| `kill <time>` | ends the client with an error code after that time, whatever it is doing: `kill 30 s`, `kill 1 m`, `kill 100 h`, `kill 2 d`. `kill 0 s` cancels it. |
| `quit` | ends the client, stopping any transfers that are still running |

## Tunnel

Start a [CrushTunnel](../CrushTunnel/Main.md) to a CrushMFT server from the prompt, then connect through it:

```
tunnel https://www.crushftp.com/
tunnel https://demo:demo@www.crushftp.com/
tunnel list
tunnel stop 1
tunnel log
connect http://127.0.0.1:55555/
```

`tunnel list` shows the tunnels with their ids (1, 2, …), `tunnel stop <id>` stops one (a stopped tunnel cannot be started again), and `tunnel log` prints its recent messages. Without a login in the URL you are asked for it.

## Jobs

Run a CrushMFT job on the server you are connected to, or a job in a local `jobs` folder:

```
job remote sftp_test_copy
job sftp_test_copy
job status sftp_test_copy
```

## The window from the prompt

`agent` starts the page that the desktop app shows and opens it in your browser; `agentui` starts it without opening the browser. See [Remote access](Remote-Access.md).

## Finding problems

| Command | Does |
|---|---|
| `dumpstack` | prints what every thread of the client is doing |
| `dumpmemory` | writes a memory dump |

## More

- [Single command](Single-Command.md): `copy`, `move`, `delete` and `rename` in one line.
- [PGP](PGP.md): encrypting and decrypting during a transfer.
- [Services](Services.md): running as a background service.
