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.
Password based authentication
Section titled “Password based authentication”If you use password based authentication you need to provide:
-p, --password
then the SFTP user password
$ connect list sftp -h 10.0.0.24 -l monitor01 -p passworddrwxrwxr-x 4096 Apr 25 11:01 .cachedrwx------ 4096 Apr 26 18:58 .configdrwx------ 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 -
.
$ connect list sftp -h 10.0.0.24 -l monitor01 -p -Enter Password:drwxrwxr-x 4096 Apr 25 11:01 .cachedrwx------ 4096 Apr 26 18:58 .configdrwx------ 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.
$ connect list sftp -h 10.0.0.24 -l monitor01 --password-file password-filedrwxrwxr-x 4096 Apr 25 11:01 .cachedrwx------ 4096 Apr 26 18:58 .configdrwx------ 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
Key based authentication
Section titled “Key based authentication”If you’d like to use SSH key based authentication you need to provide:
-i, --identity-file
then the private SSH key
For example:
$ connect list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519drwxrwxr-x 4096 Apr 25 11:01 .cachedrwx------ 4096 Apr 26 18:58 .configdrwx------ 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
$ connect list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 -k passworddrwxrwxr-x 4096 Apr 25 11:01 .cachedrwx------ 4096 Apr 26 18:58 .configdrwx------ 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 -
.
$ connect list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 -k -Enter Private Key Passphrase:drwxrwxr-x 4096 Apr 25 11:01 .cachedrwx------ 4096 Apr 26 18:58 .configdrwx------ 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.
$ connect list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 --identity-passphrase-file passphrase-filedrwxrwxr-x 4096 Apr 25 11:01 .cachedrwx------ 4096 Apr 26 18:58 .configdrwx------ 4096 Oct 27 11:42 .sshdrwxrwxr-x 4096 Jul 24 09:22 dir1drwxrwxr-x 4096 Sep 03 19:48 folderdrwxrwxr-x 393216 Sep 09 20:25 subfolder1
Target folder
Section titled “Target folder”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:
$ connect list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 -d 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
SFTP listening on non-standard port
Section titled “SFTP listening on non-standard port”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
.
$ connect list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 -d folder --port 2222-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
Timeout
Section titled “Timeout”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
:
$ connect list sftp -h 10.0.0.24 -l monitor01 -i .ssh/id_ed25519 --timeout 1drwxrwxr-x 4096 Apr 25 11:01 .cachedrwx------ 4096 Apr 26 18:58 .configdrwx------ 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
All SFTP List Options
Section titled “All SFTP List Options”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
Errors
Section titled “Errors”Please check here for information on the possible errors.