将本地文件上传到SCP服务器端
#!/bin/bash
# 本地文件路径
local_file="/path/to/local/file.txt"
# 远程服务器信息
remote_user="your_username"
remote_host="your_server_ip_or_hostname"
remote_port="22"
remote_path="/path/on/remote/server/"
# 检查本地文件是否存在
if [ ! -f "$local_file" ]; then
echo "本地文件 $local_file 不存在,请检查路径。"
exit 1
fi
# 执行 SCP 上传操作,直接覆盖远程服务器上的同名文件
scp -P "$remote_port" "$local_file" "$remote_user@$remote_host:$remote_path"
# 检查 SCP 命令的执行结果
if [ $? -eq 0 ]; then
echo "文件 $local_file 已成功上传到 $remote_user@$remote_host:$remote_path 并覆盖同名文件。"
else
echo "文件上传失败,请检查网络连接、服务器信息和权限。"
fi
上传默认覆盖服务器对应文件。请确定本地文件版本。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。