Debian 11 Bullseye
Sponsored Link

OpenSSH : SSH File Transfer (Debian)2021/08/17

 
It's possible to transfer files via SSH.
[1] It's the example for using SCP (Secure Copy).
# command ⇒ scp [Option] Source Target
# copy the [test.txt] on localhost to remote host [node01.srv.world]

debian@dlp:~$
scp ./test.txt debian@www.srv.world:~/

debian@10.0.0.30's password:    
# password of the user

test.txt                                                100%   10     0.0KB/s   00:00

# copy the [/home/debian/test.txt] on remote host [node01.srv.world] to the localhost

debian@dlp:~$
scp debian@www.srv.world:/home/debian/test.txt ./test.txt

debian@10.0.0.30's password:
test.txt                                                100%   10     0.0KB/s   00:00
[2] It's the examples to use SFTP (SSH File Transfer Protocol). SFTP server feature is enabled by default,
but if not, enable it to add the line [Subsystem sftp /usr/lib/openssh/sftp-server] in [/etc/ssh/sshd_config].
# sftp [Option] [user@host]

debian@dlp:~$
sftp debian@www.srv.world

debian@www.srv.world's password:    # password of the user
Connected to www.srv.world.
sftp>

# show current directory on remote host
sftp> pwd
Remote working directory: /home/debian

# show current directory on localhost
sftp> !pwd
/home/debian

# show files in current directory on remote host
sftp> ls -l
drwxrwxr-x    2 debian     debian            6 Aug 17 21:33 public_html
-rw-rw-r--    1 debian     debian           10 Aug 17 22:53 test.txt

# show files in current directory on localhost
sftp> !ls -l
total 4
-rw-rw-r-- 1 debian debian 10 Aug 17 21:31 test.txt

# change directory
sftp> cd public_html
sftp> pwd
Remote working directory: /home/debian/public_html

# upload a file to remote host
sftp> put test.txt debian.txt
Uploading test.txt to /home/debian/debian.txt
test.txt                           100%   10     0.0KB/s   00:00
sftp> ls -l
drwxrwxr-x    2 debian     debian            6 Aug 17 21:33 public_html
-rw-rw-r--    1 debian     debian           10 Aug 17 21:39 debian.txt
-rw-rw-r--    1 debian     debian           10 Aug 17 22:53 test.txt

# upload some files to remote host
sftp> put *.txt
Uploading test.txt to /home/debian/test.txt
test.txt                                           100%   10     0.0KB/s   00:00
Uploading test2.txt to /home/debian/test2.txt
test2.txt                                          100%    0     0.0KB/s   00:00
sftp> ls -l
drwxrwxr-x    2 debian     debian            6 Aug 17 21:33 public_html
-rw-rw-r--    1 debian     debian           10 Aug 17 21:39 debian.txt
-rw-rw-r--    1 debian     debian           10 Aug 17 21:45 test.txt
-rw-rw-r--    1 debian     debian           10 Aug 17 21:46 test2.txt

# download a file from remote host
sftp> get test.txt
Fetching /home/debian/test.txt to test.txt
/home/debian/test.txt                   100%   10     0.0KB/s   00:00

# download some files from remote host
sftp> get *.txt
Fetching /home/debian/debian.txt to debian.txt
/home/debian/debian.txt                                       100%   10     0.0KB/s   00:00
Fetching /home/debian/test.txt to test.txt
/home/debian/test.txt                                         100%   10     0.0KB/s   00:00
Fetching /home/debian/test2.txt to test2.txt
/home/debian/test2.txt                                        100%   10     0.0KB/s   00:00

# create a directory on remote host
sftp> mkdir testdir
sftp> ls -l
drwxrwxr-x    2 debian     debian            6 Aug 17 21:33 public_html
-rw-rw-r--    1 debian     debian           10 Aug 17 21:39 debian.txt
-rw-rw-r--    1 debian     debian           10 Aug 17 21:45 test.txt
-rw-rw-r--    1 debian     debian           10 Aug 17 21:46 test2.txt
drwxrwxr-x    2 debian     debian            6 Aug 17 21:53 testdir

# delete a directory on remote host
sftp> rmdir testdir
rmdir ok, `testdir' removed
sftp> ls -l
drwxrwxr-x    2 debian     debian            6 Aug 17 21:33 public_html
-rw-rw-r--    1 debian     debian           10 Aug 17 21:39 debian.txt
-rw-rw-r--    1 debian     debian           10 Aug 17 21:45 test.txt
-rw-rw-r--    1 debian     debian           10 Aug 17 21:46 test2.txt

# delete a file on remote host
sftp> rm test2.txt
Removing /home/debian/test2.txt
sftp> ls -l
drwxrwxr-x    2 debian     debian            6 Aug 17 21:33 public_html
-rw-rw-r--    1 debian     debian           10 Aug 17 21:39 debian.txt
-rw-rw-r--    1 debian     debian           10 Aug 17 21:45 test.txt

# execute commands with ![command]
sftp> !cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
.....
.....
debian:x:1001:1001::/home/debian:/bin/bash

# exit
sftp> quit
221 Goodbye.
Matched Content