Xshell5下利用sftp上传下载传输文件

sftp是Secure File Transfer Protocol的缩写,安全文件传送协议。可以为传输文件提供一种安全的加密方法。sftp 与 ftp 有着几乎一样的语法和功能。SFTP 为 SSH的一部分,是一种传输档案至 Blogger 伺服器的安全方式。其实在SSH软件包中,已经包含了一个叫作SFTP(Secure File Transfer Protocol)的安全文件传输子系统,SFTP本身没有单独的守护进程,它必须使用sshd守护进程(端口号默认是22)来完成相应的连接操作,所以从某种意义上来说,SFTP并不像一个服务器程序,而更像是一个客户端程序。SFTP同样是使用加密传输认证信息和传输的数据,所以,使用SFTP是非常安全的。但是,由于这种传输方式使用了加密/解密技术,所以传输效率比普通的FTP要低得多,如果您对网络安全性要求更高时,可以使用SFTP代替FTP。
一、连接方式
常用的方式有两种,一种直接采用sftp连接远端服务器IP
另一种则先登录远程服务器,在开启sftp功能
1、sftp [remotehost IP ]
通过sftp连接[host],端口为默认的22,用户为Linux当前登录用户。 Xshell 5 (Build 0806) Copyright (c) 2002-2015 NetSarang Computer, Inc. All rights reserved. Type `help' to learn how to use Xshell prompt. [c:\~]$ sftp 192.168.56.101 Connecting to 192.168.56.101:22... Connection established. To escape to local shell, press 'Ctrl+Alt+]'. Your current local directory is C:\Users\FieldYang\Documents\NetSarang\Xshell\Sessions Type `help' to browse available commnands. sftp:/root> 2、sftp -oPort=[port] [remotehost IP] 通过sftp连接远程服务器,指定端口[port],用户为Linux当前登录用户。 3、sftp [user]@[remotehost IP] 通过sftp连接远程服务器,端口为默认的22,指定用户[user]。 Xshell 5 (Build 0806) Copyright (c) 2002-2015 NetSarang Computer, Inc. All rights reserved. Type `help' to learn how to use Xshell prompt. [c:\~]$ sftp fieldyang@192.168.56.101 Connecting to 192.168.56.101:22... Connection established. To escape to local shell, press 'Ctrl+Alt+]'. Your current local directory is C:\Users\FieldYang\Documents\NetSarang\Xshell\Sessions Type `help' to browse available commnands. sftp:/home/fieldyang> 4、sftp -oPort=[port] [user]@[ remotehost IP] 通过sftp连接[remotehost IP],端口为[port],用户为[user]。 5、通过Xshell5与linux建立连接后,在图形用户面板上 窗口->传输新建文件,打开xftp的字符界面,如图,直接关闭即可打开一个sftp窗口 二、用法
1、基本用法
sftp:/root> help
bye finish your SFTP session
退出sftp
cd change your remote working directory
更改远程服务器工作目录
clear clear screen
清屏
exit finish your SFTP session
explore explore your local directory
导入本地目录
get download a file from the server to your local machine
从远程服务器上下载文件到本机
help give help
查找帮助
lcd change and/or print local working directory
切换本地当前工作目录
lls list contents of a local directory
列出本地当前目录的内容
lpwd print your local working directory
打印当前工作目录
ls list contents of a remote directory
列出远程服务器目录内容
mkdir create a directory on the remote server
在远程服务器上创建一个目录
mv move or rename a file on the remote server
搬移或重命名一个的远程服务器文件
put upload a file from your local machine to the server
将本机的文件上传到远程服务器
pwd print your remote working directory
打印远程服务器工作路径
quit finish your SFTP session
退出
rename move or rename a file on the remote server
搬移或重命名一个的远程服务器文件
rm delete a file
删除一个文件
rmdir remove a directory on the remote server
在远程服务器上删除一个目录删除一个目录
2、常用的为上传下载
1)、get
从远程服务器上下载一个文件存放到本地,如下:
先通过lcd切换到本地那个目录下,然后通过get file
>> lcd d:\ #表示切换到本地的d盘下
>> get ./test.sql   #这样就将当前文件下载本地的d盘下
2)、put
是将本地的文件上传到远程服务器上,如下:
>> put #在windows下弹出选择文件的窗口
3)、lcd
先通过lcd切换到本地那个目录下
>> lcd c:\ #表示切换到本地的c盘下
4)、lls
#显示当前目录下的所有文件
5)、pwd
#显示当前目录 三、各个用法实例详解
实例1、从服务器下载文件到本机
Xshell 5 (Build 0806)
Copyright (c) 2002-2015 NetSarang Computer, Inc. All rights reserved.
Type `help' to learn how to use Xshell prompt.
[c:\~]$
Connecting to 192.168.56.101:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Your current local directory is
C:\Users\FieldYang\Documents\NetSarang\Xshell\Sessions
Type `help' to browse available commnands.
sftp:/root> cd /mnt/share
#远程路径切换为/mnt/share
sftp:/mnt/share> ls –lt
drwxrwxrwx 1 1000 users 4096 Jun 16 13:39 .
drwxr-xr-x 7 root root 4096 Jun 15 14:06 ..
-rwxrwxrwx 1 1000 users 220151 Jun 15 14:26 .goutputstream-ZHJ8IY
-rwxrwxrwx 1 1000 users 19362 Jun 16 12:27 0.jpg
-rwxrwxrwx 1 1000 users 16157 Jun 16 13:39 Auth Server and SOAP proxy.docx
-rwxrwxrwx 1 1000 users 63952 Jun 16 12:29 bamquickinstall.pdf
-rwxrwxrwx 1 1000 users 7277 Jun 16 13:33 DNSmmmS.txt
-rwxrwxrwx 1 1000 users 7277 May 12 10:43 DNSS.txt
-rwxrwxrwx 1 1000 users 111395 Jun 15 15:46 libpcap-0.9.4-15.el5.x86_64.rpm
-rwxrwxrwx 1 1000 users 363677 Jun 15 14:59 ppp-2.4.4-14.1.rhel5.x86_64.rpm
-rwxrwxrwx 1 1000 users 48430 Jun 15 14:57 ppp-devel-2.4.4-14.1.rhel5.x86_64.rpm
-rwxrwxrwx 1 1000 users 86211 Jun 15 15:38 pptpd-1.4.0-1.rhel4.x86_64.rpm
-rwxrwxrwx 1 1000 users 86509 Jun 15 14:46 pptpd-1.4.0-1.rhel5.x86_64.rpm
-rwxrwxrwx 1 1000 users 220151 Jun 15 13:22 Screenshot.png
-rwxrwxrwx 1 1000 users 21789 Jun 16 13:39 Traffic Usage System alarm handling - Gateway, RadiusGWProxy, RadiusProxy Server.docx
sftp:/mnt/share> lcd d:\Field\test_sftp
#切换到本地的d盘下Field文件夹的test_sftp文件夹
Local directory is now d:\Field\test_sftp
sftp:/mnt/share> lpwd
Local directory is d:\Field\test_sftp
#打印本地文件夹路径
sftp:/mnt/share> lls
06/16/2016 05:44¤W
06/16/2016 05:44¤W
#查看本地文件夹d:\Field\test_sftp内容
sftp:/mnt/share>get ./0.jpg ./DNSmmmS.txt ./pptpd-1.4.0-1.rhel5.x86_64.rpm
#下载远程服务器/mnt/share上的0.jpg 、DNSmmmS.txt 、#pptpd-1.4.0-1.rhel5.x86_64.rpm到本地文件夹d:\Field\test_sftp中 Fetching /mnt/share/./pptpd-1.4.0-1.rhel5.x86_64.rpm to pptpd-1.4.0-1.rhel5.x86_64.rpm
sftp: received 84.4 KB in 0.64 seconds
Fetching /mnt/share/./DNSmmmS.txt to DNSmmmS.txt
sftp: received 7.10 KB in 0.02 seconds
Fetching /mnt/share/./0.jpg to 0.jpg
sftp: received 18.9 KB in 0.03 seconds
sftp:/mnt/share> lls –lt
#命令行查看是否下载成功
06/16/2016 05:47¤W
06/16/2016 05:47¤W
06/16/2016 05:47¤W 19362 0.jpg
06/16/2016 05:47¤W 7277 DNSmmmS.txt
06/16/2016 05:47¤W 86509 pptpd-1.4.0-1.rhel5.x86_64.rpm
Xshell5下利用sftp上传下载传输文件
实例2、上传本地文件到远程服务器
sftp:/mnt/share> lcd d:\Field\SNINF\
#切换本地路径到d:\Field\SNINF\
Local directory is now d:\Field\SNINF\
sftp:/mnt/share> lpwd
# 打印本地当前路径
Local directory is d:\Field\SNINF\
sftp:/mnt/share> lls -lt
02/19/2016 07:50¤W
02/19/2016 07:50¤W
12/11/2015 08:27¤W 16157 Auth Server and SOAP proxy.docx
12/11/2015 08:27¤W 464191 Check Plan--Jacky.docx
12/11/2015 08:27¤W 562801 CIMDB ¡V David.docx
12/11/2015 08:27¤W 12031 Disk Full ¡V For All Systems.docx
12/11/2015 08:27¤W 126440 EMMSC--Fox.docx
12/11/2015 08:27¤W 115928 ENUM ¡VJacky.docx
12/11/2015 08:27¤W 327650 F-Secure.docx
12/11/2015 08:27¤W 107606 GDS--Fox.docx
12/11/2015 08:27¤W 117762 GIMEI¡XFox.docx
12/11/2015 08:27¤W 310862 GUP CGUP ¡ΠRay.docx
12/11/2015 08:27¤W 650939 IP call --Sharon.docx
12/11/2015 08:27¤W 779957 Mex health check--Niker.docx
12/11/2015 08:27¤W 124195 NetScout (DPI)¡XFox.docx
12/11/2015 08:27¤W 198426 POC--Jacky.docx
12/11/2015 08:27¤W 326368 Radius Proxy -Niker.docx
12/11/2015 08:27¤W 190044 SMTP health check--Niker.docx
12/11/2015 08:27¤W 45643 Stretti DFS¡XSharon.docx
12/11/2015 08:27¤W 233654 Stretti DISC ¡VJacky.docx
12/11/2015 08:27¤W 449498 Traffic Router Health Check¡XDavid.docx
12/11/2015 08:27¤W 21789 Traffic Usage System alarm handling - Gateway, RadiusGWProxy, RadiusProxy Server.docx
12/11/2015 08:27¤W 734859 Video Transcoder¡XDavid.docx
12/11/2015 08:27¤W 14815 Virtual Browser.docx
12/11/2015 08:27¤W 22554 ZMMSC.docx
12/11/2015 08:27¤W 219776 ZProxy ¡ΠFox.docx
12/11/2015 08:27¤W 221199 ZWAPGW NZWAPGW ¡ΠFox.docx
sftp:/mnt/share> put
Uploading Traffic Usage System alarm handling - Gateway, RadiusGWProxy, RadiusProxy Server.docx to remote:/mnt/share/Traffic Usage System alarm handling - Gateway, RadiusGWProxy, RadiusProxy Server.docx
sftp: sent 21.2 KB in 0.01 seconds
#在弹出的Windows框中选择文件上传 注意上传路径与当前路径要相同
sftp:/mnt/share> put
Uploading Virtual Browser.docx to remote:/mnt/share/Virtual Browser.docx
sftp: sent 14.4 KB in 0.02 seconds
sftp:/mnt/share> put
Uploading Check Plan--Jacky.docx to remote:/mnt/share/Check Plan--Jacky.docx
sftp: sent 453 KB in 0.05 seconds
sftp:/mnt/share> put
Uploading ZMMSC.docx to remote:/mnt/share/ZMMSC.docx
sftp: sent 22.0 KB in 0.00 seconds
sftp:/mnt/share> ls -lt
drwxrwxrwx 1 1000 users 4096 Jun 16 13:54 .
drwxr-xr-x 7 root root 4096 Jun 15 14:06 ..
-rwxrwxrwx 1 1000 users 220151 Jun 15 14:26 .goutputstream-ZHJ8IY
-rwxrwxrwx 1 1000 users 19362 Jun 16 12:27 0.jpg
-rwxrwxrwx 1 1000 users 16157 Jun 16 13:39 Auth Server and SOAP proxy.docx
-rwxrwxrwx 1 1000 users 63952 Jun 16 12:29 bamquickinstall.pdf
-rwxrwxrwx 1 1000 users 464191 Jun 16 13:53 Check Plan--Jacky.docx
-rwxrwxrwx 1 1000 users 7277 Jun 16 13:33 DNSmmmS.txt
-rwxrwxrwx 1 1000 users 7277 May 12 10:43 DNSS.txt
-rwxrwxrwx 1 1000 users 111395 Jun 15 15:46 libpcap-0.9.4-15.el5.x86_64.rpm
-rwxrwxrwx 1 1000 users 363677 Jun 15 14:59 ppp-2.4.4-14.1.rhel5.x86_64.rpm
-rwxrwxrwx 1 1000 users 48430 Jun 15 14:57 ppp-devel-2.4.4-14.1.rhel5.x86_64.rpm
-rwxrwxrwx 1 1000 users 86211 Jun 15 15:38 pptpd-1.4.0-1.rhel4.x86_64.rpm
-rwxrwxrwx 1 1000 users 86509 Jun 15 14:46 pptpd-1.4.0-1.rhel5.x86_64.rpm
-rwxrwxrwx 1 1000 users 220151 Jun 15 13:22 Screenshot.png
-rwxrwxrwx 1 1000 users 21789 Jun 16 13:52 Traffic Usage System alarm handling - Gateway, RadiusGWProxy, RadiusProxy Server.docx
-rwxrwxrwx 1 1000 users 14815 Jun 16 13:53 Virtual Browser.docx
-rwxrwxrwx 1 1000 users 22554 Jun 16 13:54 ZMMSC.docx
sftp:/mnt/share>
实例3、在远程服务器创建删除目录
sftp:/mnt/share> mkdir /mnt/share/test
#在远程服务器上创建目录/mnt/share/test
sftp:/mnt/share> cd /mnt/share/test
sftp:/mnt/share/test> pwd
#查看是否创建成功
Remote directory is /mnt/share/test
sftp:/mnt/share/test> cd /mnt/share/
sftp:/mnt/share> rmdir /test
cannot remove /test: no such a directory
sftp:/mnt/share> rmdir /mnt/share/test
#删除刚创建的目录/mnt/share/test
sftp:/mnt/share> cd /mnt/share/test
cannot change to /mnt/share/test: no such a directory
#确认是否删除成功
实例4、在远程服务器删除文件
sftp:/mnt/share> rm ./ZMMSC
#删除远程服务器/mnt/share上的文件ZMMSC.docx,./表示当前目录
cannot delete /mnt/share/./ZMMSC: no such a file
sftp:/mnt/share> rm ./ZMMSC.docx
deleted /mnt/share/./ZMMSC.docx
sftp:/mnt/share> rm ./Traffic Usage System alarm handling - Gateway, RadiusGWProxy, RadiusProxy Server.docx
usage: rm file
sftp:/mnt/share> rm ./DNSS.txt
deleted /mnt/share/./DNSS.txt
sftp:/mnt/share> ls
#查看是否成功删除
drwxrwxrwx 1 1000 users 4096 Jun 16 14:25 .
drwxr-xr-x 7 root root 4096 Jun 15 14:06 ..
-rwxrwxrwx 1 1000 users 220151 Jun 15 14:26 .goutputstream-ZHJ8IY
-rwxrwxrwx 1 1000 users 19362 Jun 16 12:27 0.jpg
-rwxrwxrwx 1 1000 users 16157 Jun 16 13:39 Auth Server and SOAP proxy.docx
-rwxrwxrwx 1 1000 users 63952 Jun 16 12:29 bamquickinstall.pdf
-rwxrwxrwx 1 1000 users 464191 Jun 16 13:53 Check Plan--Jacky.docx
-rwxrwxrwx 1 1000 users 7277 Jun 16 13:33 DNSmmmS.txt
-rwxrwxrwx 1 1000 users 111395 Jun 15 15:46 libpcap-0.9.4-15.el5.x86_64.rpm
-rwxrwxrwx 1 1000 users 363677 Jun 15 14:59 ppp-2.4.4-14.1.rhel5.x86_64.rpm
-rwxrwxrwx 1 1000 users 48430 Jun 15 14:57 ppp-devel-2.4.4-14.1.rhel5.x86_64.rpm
-rwxrwxrwx 1 1000 users 86211 Jun 15 15:38 pptpd-1.4.0-1.rhel4.x86_64.rpm
-rwxrwxrwx 1 1000 users 86509 Jun 15 14:46 pptpd-1.4.0-1.rhel5.x86_64.rpm
-rwxrwxrwx 1 1000 users 220151 Jun 15 13:22 Screenshot.png
-rwxrwxrwx 1 1000 users 21789 Jun 16 13:52 Traffic Usage System alarm handling - Gateway, RadiusGWProxy, RadiusProxy Server.docx
-rwxrwxrwx 1 1000 users 14815 Jun 16 13:53 Virtual Browser.docx
sftp:/mnt/share>

  

上一篇:C#中的可空值类型


下一篇:selenium3 无人工干预地自动下载某个文件