---
title: "Ubuntu下通过sftp远程登录linux系统，并实现上传、下载文件"
author: "weistar"
date: "2013-07-16T17:58:15Z"
tags: []
categories: ["操作系统"]
slug: "ubuntu-sftp-linux"
draft: true
lastmod: "2013-07-16T17:58:15Z"
id: 1908025
url: "https://weistar.iteye.com/blog/1908025"
---

## Ubuntu下通过sftp远程登录linux系统，并实现上传、下载文件

在Windows下可以使用SecureCRT远程登录Ubuntu，并使用rz、sz实现上传、下载文件。  
如果在Ubuntu下使用ssh命令远程登录另一台Ubuntu，如何实现上传、下载呢？答案是：sftp。  
sftp是secure file transfer program的缩写，是隶属于SSH的一个应用，在安装好SSH之后就已包括此命令，其使用方式类似于ftp而更加安全。  
Ubuntu 10.04中语法如下：  
 sftp \[-1Cv] \[-B buffer\_size] \[-b batchfile] \[-F ssh\_config] \[-o ssh\_option] \[-P sftp\_server\_path] \[-R num\_requests]  
      \[-S program] \[-s subsystem | sftp\_server] host  
 sftp \[user@]host\[:file ...]  
 sftp \[user@]host\[:dir\[/]]  
 sftp -b batchfile \[user@]host

Ubuntu 10.10中语法如下：  
 sftp \[-1246Cpqrv] \[-B buffer\_size] \[-b batchfile] \[-c cipher] \[-D sftp\_server\_path] \[-F ssh\_config] \[-i identity\_file]  
      \[-o ssh\_option] \[-P port] \[-R num\_requests] \[-S program] \[-s subsystem | sftp\_server] host  
 sftp \[user@]host\[:file ...]  
 sftp \[user@]host\[:dir\[/]]  
 sftp -b batchfile \[user@]host

以下是其用法举例：  
**登录（登录成功后，命令行提示符将变为“sftp&gt;”）**  
sftp chen@100.130.100.99  #以chen用户身份远程登录100.130.100.99主机，默认端口号为22  
sftp -o Port=222 chen@100.130.100.99  #指定SSH端口号来远程登录主机  
sftp -o Port=222 chen@100.130.100.99:/home/chen/version/  #指定SSH端口号来远程登录主机，并切换到/home/chen/version/目录  
sftp -P 222 chen@100.130.100.99  #指定SSH端口号来远程登录主机（此方式只能在Ubuntu 10.10中使用）  
注：登录到远程主机后才可执行如下命令。

**交互命令：**  
上传  
put new.txt /home/chen/#将本地当前目录下的new.txt上传到远程主机的/home/chen/目录  
下载  
get /home/chen/new.txt #将远程主机的/home/chen/new.txt文件下载到本地当前目录  
get /home/chen/new.txt /home/zhao/#将远程主机的/home/chen/new.txt文件下载到本地/home/zhao/目录

**远程命令：**  
切换目录  
cd pro #切换到pro目录  
更改权限  
chmod 755 my-shell.sh #将my-shell.sh文件的权限改为755  
查看磁盘使用情况  
df -h #查看磁盘使用情况  
列出目录内容  
ls -l #以详细列表的方式显示文件和目录  
新建目录  
mkdir newdir #在当前目录下新建newdir目录  
显示当前目录的完整路径  
pwd#显示当前目录的完整路径  
重命名  
rename my-shell.sh new-shell.sh #将my-shell.sh文件重命名为new-shell.sh  
删除文件  
rm new-shell.sh#删除new-shell.sh文件  
删除空目录  
rmdir pro#删除空目录pro  
创建链接  
ln abc.txt abc.ln   #为abc.txt建立链接文件abc.ln

**本地命令：（本地命令一般会在命令前添加l以代表local）**  
切换目录  
lcd pro #将本地目录切换到pro目录  
列出目录内容  
lls -l#以详细列表的方式显示本地的文件和目录  
新建目录  
lmkdir newdir #在本地当前目录下新建newdir目录  
显示当前目录的完整路径  
lpwd#显示本地当前目录的完整路径  
执行任何本地命令  
!date #使用本地shell来执行命令，!之后可以是任何本机能够识别的命令  
!#切换到本地shell，以便执行其他命令，如果想退出本地shell，可以执行exit以返回远程环境

**退出：**  
bye #退出sftp  
exit #同上  
quit #同上