SCP:将本地文件上传到Linux服务器

本文详细介绍了如何使用SCP命令进行文件和目录的传输,包括从服务器下载文件、上传本地文件到服务器、下载整个目录以及上传目录到服务器的具体操作方法。

转载自https://blog.youkuaiyun.com/netlai/article/details/79756260

scp -P 端口 c://xxxx.txt user@ip:/home/root
注意:

-P 大写

-i 公钥

1、从服务器上下载文件

scp username@servername:/path/filename /var/www/local_dir(本地目录)

例如scp root@192.168.0.101:/var/www/test.txt 把192.168.0.101上的/var/www/test.txt 的文件下载到/var/www/local_dir(本地目录)

2、上传本地文件到服务器

scp /path/filename username@servername:/path  

例如scp /var/www/test.php root@192.168.0.101:/var/www/ 把本机/var/www/目录下的test.php文件上传到192.168.0.101这台服务器上的/var/www/目录中

3、从服务器下载整个目录

scp -r username@servername:/var/www/remote_dir/(远程目录) /var/www/local_dir(本地目录)

例如:scp -r root@192.168.0.101:/var/www/test /var/www/

4、上传目录到服务器

scp  -r local_dir username@servername:remote_dir

例如:scp -r test root@192.168.0.101:/var/www/ 把当前目录下的test目录上传到服务器的/var/www/ 目录
注意:一定是从根目录开始

要将本地文件上传Linux服务器,可以使用多种命令行工具,其中最常用的是`scp`和`rsync`。以下是这两种工具的使用方法: ### 使用 `scp` `scp`(secure copy)是一个基于SSH的文件传输工具,适用于在本地和远程主机之间安全地复制文件。 1. **上传单个文件**: ```bash scp /path/to/local/file username@remote_host:/path/to/remote/directory ``` 2. **上传整个目录**: ```bash scp -r /path/to/local/directory username@remote_host:/path/to/remote/directory ``` 在上述命令中: - `/path/to/local/file` 或 `/path/to/local/directory` 是本地文件的路径。 - `username` 是远程服务器的用户名。 - `remote_host` 是远程服务器的IP地址或主机名。 - `/path/to/remote/directory` 是远程服务器上的目标路径。 ### 使用 `rsync` `rsync` 是一个功能强大的文件同步工具,适用于在本地和远程主机之间同步文件。 1. **上传单个文件**: ```bash rsync -avz /path/to/local/file username@remote_host:/path/to/remote/directory ``` 2. **上传整个目录**: ```bash rsync -avz /path/to/local/directory/ username@remote_host:/path/to/remote/directory ``` 在上述命令中: - `-a` 表示归档模式,递归复制并保持文件属性。 - `-v` 表示详细输出。 - `-z` 表示压缩文件数据。 - `/path/to/local/file` 或 `/path/to/local/directory/` 是本地文件的路径。 - `username` 是远程服务器的用户名。 - `remote_host` 是远程服务器的IP地址或主机名。 - `/path/to/remote/directory` 是远程服务器上的目标路径。 ### 示例 假设你要将本地的 `example.txt` 文件上传到远程服务器的 `/home/user/` 目录下,用户名为 `user`,服务器地址为 `192.168.1.100`: ```bash scp example.txt user@192.168.1.100:/home/user/ ``` 或者使用 `rsync`: ```bash rsync -avz example.txt user@192.168.1.100:/home/user/ ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值