Search code examples
linuxshellsshscp

Protocol not available error for scp on Linux


I'm trying to copy windows file to linux, but the scp command always see 'Protocol not available', bellow is my code:

#!/bin/bash
client_IP='192.168.0.47'
windows_log_folder='E:\project\robot_framework\第一个测试项目\logs'
argfile_path='E:\project\robot_framework\第一个测试项目\logs\argfile.txt'
time_folder=`date +%Y-%m-%T`
echo ${time_folder}
base_path=$1
echo $base_path
log_folder="${base_path}/logs/${time_folder}"
mkdir "${log_folder}"
echo "${log_folder}"
echo "baimng.zhang@${client_IP}:${argfile_path}"
scp -p baiming.zhang@${client_IP}:${argfile_path} '${log_folder}'
ssh baiming.zhang@${client_IP} "pybot.bat --argumentfile ${argfile_path} E:\project\robot_framework\第一个测试项目" #works fine

files=`ssh baiming.zhang@${client_IP} "dir /b /a:-D ${windows_log_folder}"`
for file in $files
do
   path="${windows_log_folder}\\${file}"
   echo $path
   scp -p baiming.zhang@${client_IP}:${path} '${log_folder}' #**error appears  in this line**
done

enter image description here


Solution

  • there is a whitespace in the file name which I get from the windows command, I use below code the trim the file name, then it works fine.

    for file in $files
    do
        new_file="$(echo -e "${file}" | tr -d '[:space:]')"
        path=${folder}${new_file}
        path="${windows_log_folder}\\${new_file}"
        echo "try to copy ${path} to ${log_folder}"
        scp -p baiming.zhang@${client_IP}:${path} ${log_folder}
    done