Skip to content

SFTP Listing

In order to list files in a remote SFTP location you need to execute connect list sftp followed by two mandatory parameters:

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

You can also provide an optional folder with:

  • -d, --folder then the folder name

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
Terminal window
$ connect list sftp -h 10.0.0.24 -l monitor01 -p password
2025/05/22 10:41:49 INFO Listing sftp://[email protected]:
drwxrwxr-x 4096 Apr 25 11:01 .cache
drwx------ 4096 Apr 26 18:58 .config
drwx------ 4096 Jul 13 15:21 .ssh
-rw------- 11503 Jul 18 21:11 .bash_history
-rw-r--r-- 220 Feb 25 12:03 .bash_logout
-rw-r--r-- 3771 Feb 25 12:03 .bashrc
-rw-r--r-- 807 Feb 25 12:03 .profile

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

Terminal window
$ connect list sftp -h 10.0.0.24 -l monitor01 -p -
Enter Password:
025/05/22 10:52:34 INFO Listing sftp://[email protected]:
drwxrwxr-x 4096 Apr 25 11:01 .cache
drwx------ 4096 Apr 26 18:58 .config
drwx------ 4096 Jul 13 15:21 .ssh
-rw------- 11503 Jul 18 21:11 .bash_history
-rw-r--r-- 220 Feb 25 12:03 .bash_logout
-rw-r--r-- 3771 Feb 25 12:03 .bashrc
-rw-r--r-- 807 Feb 25 12:03 .profile

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 list sftp -h 10.0.0.24 -l monitor01 --password-file password-file
2025/05/22 10:53:17 INFO Listing sftp://[email protected]:
drwxrwxr-x 4096 Apr 25 11:01 .cache
drwx------ 4096 Apr 26 18:58 .config
drwx------ 4096 Jul 13 15:21 .ssh
-rw------- 11503 Jul 18 21:11 .bash_history
-rw-r--r-- 220 Feb 25 12:03 .bash_logout
-rw-r--r-- 3771 Feb 25 12:03 .bashrc
-rw-r--r-- 807 Feb 25 12:03 .profile

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 list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519
2025/05/22 10:53:44 INFO Listing sftp://[email protected]:
drwxrwxr-x 4096 Apr 25 11:01 .cache
drwx------ 4096 Apr 26 18:58 .config
drwx------ 4096 Jul 13 15:21 .ssh
-rw------- 11503 Jul 18 21:11 .bash_history
-rw-r--r-- 220 Feb 25 12:03 .bash_logout
-rw-r--r-- 3771 Feb 25 12:03 .bashrc
-rw-r--r-- 807 Feb 25 12:03 .profile

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

  • -k, --identity-passphrase then the optional password to the private key
Terminal window
$ connect list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 -k password
2025/05/22 10:56:58 INFO Listing sftp://[email protected]:
drwxrwxr-x 4096 Apr 25 11:01 .cache
drwx------ 4096 Apr 26 18:58 .config
drwx------ 4096 Jul 13 15:21 .ssh
-rw------- 11503 Jul 18 21:11 .bash_history
-rw-r--r-- 220 Feb 25 12:03 .bash_logout
-rw-r--r-- 3771 Feb 25 12:03 .bashrc
-rw-r--r-- 807 Feb 25 12:03 .profile

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

Terminal window
$ connect list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 -k -
Enter Private Key Passphrase:
2025/05/22 10:57:35 INFO Listing sftp://[email protected]:
drwxrwxr-x 4096 Apr 25 11:01 .cache
drwx------ 4096 Apr 26 18:58 .config
drwx------ 4096 Jul 13 15:21 .ssh
-rw------- 11503 Jul 18 21:11 .bash_history
-rw-r--r-- 220 Feb 25 12:03 .bash_logout
-rw-r--r-- 3771 Feb 25 12:03 .bashrc
-rw-r--r-- 807 Feb 25 12:03 .profile

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 list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 --identity-passphrase-file passphrase-file
2025/05/22 10:58:55 INFO Listing sftp://[email protected]:
drwxrwxr-x 4096 Apr 25 11:01 .cache
drwx------ 4096 Apr 26 18:58 .config
drwx------ 4096 Oct 27 11:42 .ssh
drwxrwxr-x 4096 Jul 24 09:22 dir1
drwxrwxr-x 4096 Sep 03 19:48 folder
drwxrwxr-x 393216 Sep 09 20:25 subfolder1

You can also specify the optional target folder to list with:

  • -d, --folder remote folder name

If you don’t specify the folder, the command will list home folder of the SFTP user.

For example:

Terminal window
$ connect list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 -d folder
2025/05/22 11:01:04 INFO Listing sftp://[email protected]:folder
-rw-rw-r-- 1024 Sep 03 19:48 file1.txt
-rw-rw-r-- 1024 Sep 03 19:48 file2.txt
-rw-rw-r-- 1024 Sep 03 19:48 file3.txt

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 command lists the content of folder folder of server sftp://[email protected] listening on port 2222/TCP .

Terminal window
$ connect list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 -d folder --port 2222
2025/05/22 11:38:24 INFO Listing sftp://[email protected]:2222:folder
-rw-rw-r-- 1024 Sep 03 19:48 file1.txt
-rw-rw-r-- 1024 Sep 03 19:48 file2.txt
-rw-rw-r-- 1024 Sep 03 19:48 file3.txt

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 command list the contents of sftp://[email protected] with network timeout set to 1s:

Terminal window
$ connect list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 --timeout 1
2025/05/22 11:39:03 INFO Listing sftp://[email protected]:
drwxrwxr-x 4096 Apr 25 11:01 .cache
drwx------ 4096 Apr 26 18:58 .config
drwx------ 4096 Jul 13 15:21 .ssh
-rw------- 11503 Jul 18 21:11 .bash_history
-rw-r--r-- 220 Feb 25 12:03 .bash_logout
-rw-r--r-- 3771 Feb 25 12:03 .bashrc
-rw-r--r-- 807 Feb 25 12:03 .profile
Terminal window
Usage:
connect list 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:
-d, --folder string Folder to list files
--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.