SCP command 프로그램

프로그래밍|2018. 5. 17. 11:41

I am going to share my program that I made whenever I had time.

I made it using SCP command.


SCP uses Secure Shell (SSH) to transfer file between client and remote server, It's fast and secure.

In this article, I will show you two examples.


1. First example - copying file from several remote server


If you need to transfer file to several remote server, You can use it below program.

The program requires file that has many linux ip or username information like below.

nklee@172.19.136.18
nklee@172.19.136.18
nklee@172.19.136.18
#!/bin/sh

if [ $# -lt 3 ]
then
    echo "Usage : $0 {로컬파일or디렉토리} {원격경로} {서버파일리스트}"
    exit 1
fi

servers=`cat $3`

for server in $servers
do
    echo "-------------------------------------------------"
    echo "scp -r $1 ${server}:$2"
    echo "-------------------------------------------------"
    scp -r $1 ${server}:$2
    echo "\n"
done

You can use following UNIX command.

1
$ ./scp_download.sh /home/nklee/index.html . servers
cs




2. Second example - copying file to several remote server


If you need to transfer file from several remote servers, You can use it below program.

#!/bin/sh

if [ $# -lt 3 ]
then
    echo "Usage : $0 {로컬파일or디렉토리} {원격경로} {서버파일리스트}"
    exit 1
fi

servers=`cat $3`

for server in $servers
do
    echo "-------------------------------------------------"
    echo "scp -r $1 ${server}:$2"
    echo "-------------------------------------------------"
    scp -r $1 ${server}:$2
    echo "\n"
done

You can use following UNIX command.

1
$ ./scp_upload.sh ./index.html /home/nklee/test servers
cs



Thanks for reading this article so far.

If you have any questions or feedback then please write your comment.

댓글()