Automate scp file transfer using a shell script

前端 未结 13 1021
误落风尘
误落风尘 2020-11-30 17:24

I have some n number of files in a directory on my unix system. Is there a way to write a shellscript that will transfer all those files via scp to a specified remote system

13条回答
  •  自闭症患者
    2020-11-30 18:19

    here's bash code for SCP with a .pem key file. Just save it to a script.sh file then run with 'sh script.sh'

    Enjoy

    #!/bin/bash
    #Error function
    function die(){
    echo "$1"
    exit 1
    }
    
    Host=ec2-53-298-45-63.us-west-1.compute.amazonaws.com
    User=ubuntu
    #Directory at sent destination
    SendDirectory=scp
    #File to send at host
    FileName=filetosend.txt
    #Key file
    Key=MyKeyFile.pem
    
    echo "Aperture in Process...";
    
    #The code that will send your file scp
    scp -i $Key $FileName $User@$Host:$SendDirectory || \
    die "@@@@@@@Houston we have problem"
    
    echo "########Aperture Complete#########";
    

提交回复
热议问题