Skip to content

SFTP Connection Testing

In order to test SFTP connection to a remote server you need to execute connect test sftp followed by two mandatory parameters:

  • -h, --host then the remote IP
  • -l, --login then remote SFTP user login

Depending on the type of authentication you need to either use -p, --password or --password-file for password based authentication or the -i, --identity-file for key based authentication.

If you use password based authentication you need to provide:

  • -p, --password then the SFTP user password

For example:

Terminal window
$ connect test sftp -h 10.0.0.24 -l monitor01 -p password
2025/05/19 17:53:40 INFO Testing connection to sftp://[email protected]
2025/05/19 17:53:42 INFO Connection successful

Application can also prompt you for a password. Just put -p -.

Terminal window
$ connect test sftp -h 10.0.0.24 -l monitor01 -p -
Enter Password:
2025/05/19 17:59:09 INFO Testing connection to sftp://[email protected]
2025/05/19 17:59:11 INFO Connection successful

To secure the solution it’s also possible to provide the password stored in a file with --password-file and then the file containing the password.

Terminal window
$ connect test sftp -h 10.0.0.24 -l monitor01 --password-file password-file
2025/05/19 18:00:47 INFO Testing connection to sftp://[email protected]
2025/05/19 18:00:50 INFO Connection successful

If you’d like to use SSH key based authentication you need to provide:

  • -i, --identity-file then the private SSH key

For example:

Terminal window
$ connect test sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519
2025/05/19 18:03:16 INFO Testing connection to sftp://[email protected]
2025/05/19 18:03:17 INFO Connection successful

If your key is password protected you can provide the password using:

  • -k, --identity-passphrase then the optional password to the private key
Terminal window
$ connect test sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 -k password
2025/05/19 18:04:16 INFO Testing connection to sftp://[email protected]
2025/05/19 18:0:17 INFO Connection successful

Application can also prompt you for the key password. Just put -k -.

Terminal window
$ connect test sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 -k -
Enter Private Key Passphrase:
2025/05/19 18:05:35 INFO Testing connection to sftp://[email protected]
2025/05/19 18:05:37 INFO Connection successful

To secure the solution it’s also possible to provide key password stored in a file with --identity-passphrase-file and then the file containing the password to the key.

Terminal window
$ connect test sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 --identity-passphrase-file passphrase-file
2025/05/19 18:06:36 INFO Testing connection to sftp://[email protected]
2025/05/19 18:06:38 INFO Connection successful

Optionally you can specify the target port the remote server is listening on (if it’s different than 22/TCP).

  • --port then the target TCP port

For example, below tests the connection to sftp://[email protected] port 2222/TCP.

Terminal window
$ connect test sftp -h 10.0.0.24 -l monitor01 -p password --port 2222
2025/05/19 18:14:23 INFO Testing connection to sftp://[email protected]:2222
2025/05/19 18:14:24 INFO Connection successful

There’s an optional parameter to set the timeout for network operations. By default it’s set to 30s however for servers on a local network you may wish to reduce the timeout and for slow servers or servers far away you may wish to extend the timeout.

  • --timeout number of seconds

Below example tests the connection to sftp://[email protected] with network timeout set to 1s:

Terminal window
$ connect test sftp -h 10.0.0.24 -l monitor01 -p password --timeout 1
2025/05/19 18:16:42 INFO Testing connection to sftp://[email protected]
2025/05/19 18:16:43 INFO Connection successful
Terminal window
Usage:
connect test sftp [command] [flags]
Flags:
-h, --host string Destination sftp host
-i, --identity-file string Private key file to use for authentication
-k, --identity-passphrase string Private key passphrase
--identity-passphrase-file string Private key passphrase file
--idle uint Timeout for no network activity in seconds (default 60)
-l, --login string Destination sftp host login
-p, --password string Destination sftp host password
--password-file string Destination sftp host password file
--port uint Destination sftp host port (default 22)
-t, --timeout uint Timeout for network operations in seconds (default 30)
Global Flags:
--godebug Turns on debug mode
--help Prints help for the command
--log-format string Log output format: text|json (default "text")
--no-color Do not use colors in logs
--quiet Makes no output

Please check here for information on the possible errors.