将本地文件上传到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

上传默认覆盖服务器对应文件。请确定本地文件版本。

发表回复

登录... 后才能评论