我正在尝试运行curl命令以使用sftp下载文件,然后检查该文件是否已下载,但不知何故我的代码每次都打印“文件已成功下载”,即使文件未下载也是如此。
这是我的剧本:
#!bin/bash
curl -k -u "user:user" -ssl -o file.zip sftp:domain
if [[ $? -ne 0 ]]; then
echo "Failed to download file"
exit -1
fi
echo "File downloaded successfully"
答案 0 :(得分:0)
尝试使用--write-out
选项作为
#!bin/bash
rcode=$(curl --silent --write-out '%{response_code}' -k -u "user:user" -ssl -o file.zip sftp:domain)
if [[ "$rcode" -ne 0 ]]; then
echo "Failed to download file"
exit -1
fi
echo "File downloaded successfully"
对于404 http响应
rcode=$curl --silent --write-out '%{response_code})' http://localhost:8080/tyu
echo "$rcode"
404
sftp response codes,成功为0。