• 【转载】xShell5 利用 sftp 在本地和服务器之间传输文件


    sftp是Secure File TransferProtocol的缩写,安全文件传送协议。可以为传输文件提供一种安全的加密方法。sftp与 ftp有着几乎一样的语法和功能。SFTP为 SSH的一部分,是一种传输档案至Blogger伺服器的安全方式。其实在SSH软件包中,已经包含了一个叫作SFTP(Secure File Transfer Protocol)的安全文件传输子系统,SFTP本身没有单独的守护进程,它必须使用sshd守护进程(端口号默认是22)来完成相应的连接操作,所以从某种意义上来说,SFTP并不像一个服务器程序,而更像是一个客户端程序。SFTP同样是使用加密传输认证信息和传输的数据,所以,使用SFTP是非常安全的。但是,由于这种传输方式使用了加密/解密技术,所以传输效率比普通的FTP要低得多,如果您对网络安全性要求更高时,可以使用SFTP代替FTP

    一、连接方式

    常用的方式有两种,一种直接采用sftp连接远端服务器IP

    另一种则先登录远程服务器,在开启sftp功能

    1sftp [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:~]$ sftp192.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:UsersFieldYangDocumentsNetSarangXshellSessions

    Type `help' to browse available commnands.

    sftp:/root>

    2sftp -oPort=[port][remotehost IP]

    通过sftp连接远程服务器,指定端口[port],用户为Linux当前登录用户。

    3sftp[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:UsersFieldYangDocumentsNetSarangXshellSessions

    Type `help' to browse available commnands.

    sftp:/home/fieldyang>

    4sftp -oPort=[port][user]@[ remotehost IP]

    通过sftp连接[remotehost IP],端口为[port],用户为[user]。

    5、通过Xshell5linux建立连接后,在图形用户面板上 窗口->传输新建文件,打开xftp的字符界面,如图,直接关闭即可打开一个sftp窗口

     

    二、用法

    1、基本用法

    sftp:/root> help

    bye    finish your SFTP session

          退出sftp

    cd     change your remote workingdirectory

          更改远程服务器工作目录

    clear  clear screen

          清屏

    exit   finish your SFTP session

    explore explore your local directory

          导入本地目录

    get    download a file from theserver to your local machine

          从远程服务器上下载文件到本机

    help   give help

          查找帮助

    lcd    change and/or print localworking directory

          切换本地当前工作目录

    lls    list contents of a localdirectory

          列出本地当前目录的内容

    lpwd   print your local workingdirectory

          打印当前工作目录

    ls     list contents of a remotedirectory

          列出远程服务器目录内容

    mkdir  create a directory on theremote server

          在远程服务器上创建一个目录

    mv     move or rename a file onthe remote server

          搬移或重命名一个的远程服务器文件

    put    upload a file from yourlocal machine to the server

          将本机的文件上传到远程服务器

    pwd    print your remote workingdirectory

          打印远程服务器工作路径

    quit   finish your SFTP session

          退出

    rename move or rename a file onthe remote server

          搬移或重命名一个的远程服务器文件

    rm     delete a file

          删除一个文件

    rmdir  remove a directory on theremote 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-2015NetSarang Computer, Inc. All rights reserved.

    Type `help' to learn howto use Xshell prompt.

    [c:~]$

    Connecting to192.168.56.101:22...

    Connection established.

    To escape to local shell,press 'Ctrl+Alt+]'.

    Your current localdirectory is

    C:UsersFieldYangDocumentsNetSarangXshellSessions

    Type `help' to browseavailable 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:270.jpg

    -rwxrwxrwx   1 1000    users      16157 Jun 16 13:39Auth Server and SOAP proxy.docx

    -rwxrwxrwx   1 1000    users      63952 Jun 16 12:29bamquickinstall.pdf

    -rwxrwxrwx   1 1000    users       7277 Jun 16 13:33DNSmmmS.txt

    -rwxrwxrwx   1 1000    users       7277 May 12 10:43DNSS.txt

    -rwxrwxrwx   1 1000    users     111395 Jun 15 15:46libpcap-0.9.4-15.el5.x86_64.rpm

    -rwxrwxrwx   1 1000    users     363677 Jun 15 14:59ppp-2.4.4-14.1.rhel5.x86_64.rpm

    -rwxrwxrwx   1 1000    users      48430 Jun 15 14:57ppp-devel-2.4.4-14.1.rhel5.x86_64.rpm

    -rwxrwxrwx   1 1000    users      86211 Jun 15 15:38pptpd-1.4.0-1.rhel4.x86_64.rpm

    -rwxrwxrwx   1 1000    users      86509 Jun 15 14:46pptpd-1.4.0-1.rhel5.x86_64.rpm

    -rwxrwxrwx   1 1000    users     220151 Jun 15 13:22Screenshot.png

    -rwxrwxrwx   1 1000    users      21789 Jun 16 13:39Traffic Usage System alarm handling - Gateway, RadiusGWProxy, RadiusProxyServer.docx 

    sftp:/mnt/share> lcd d:Field est_sftp 

    #切换到本地的d盘下Field文件夹的test_sftp文件夹

    Local directory is nowd:Field est_sftp

    sftp:/mnt/share> lpwd

    Local directory isd:Field est_sftp

    #打印本地文件夹路径

    sftp:/mnt/share> lls

    06/16/2016 05:44¤W   <DIR>             .

    06/16/2016 05:44¤W   <DIR>             ..

    #查看本地文件夹d:Field est_sftp内容

    sftp:/mnt/share>get ./0.jpg ./DNSmmmS.txt./pptpd-1.4.0-1.rhel5.x86_64.rpm

    #下载远程服务器/mnt/share上的0.jpgDNSmmmS.txt#pptpd-1.4.0-1.rhel5.x86_64.rpm到本地文件夹d:Field est_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 in0.64 seconds

    Fetching/mnt/share/./DNSmmmS.txt to DNSmmmS.txt

    sftp: received 7.10 KB in0.02 seconds

    Fetching/mnt/share/./0.jpg to 0.jpg

    sftp: received 18.9 KB in0.03 seconds 

    sftp:/mnt/share> lls –lt

    #命令行查看是否下载成功

    06/16/2016 05:47¤W   <DIR>             .

    06/16/2016 05:47¤W   <DIR>             ..

    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


    实例2、上传本地文件到远程服务器

    sftp:/mnt/share> lcd d:FieldSNINF

    #切换本地路径到d:FieldSNINF

    Local directory is nowd:FieldSNINF

    sftp:/mnt/share> lpwd

    #打印本地当前路径

    Local directory isd:FieldSNINF

    sftp:/mnt/share> lls -lt

    02/19/2016 07:50¤W   <DIR>             .

    02/19/2016 07:50¤W   <DIR>             ..

    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 UsageSystem alarm handling - Gateway, RadiusGWProxy, RadiusProxy Server.docx toremote:/mnt/share/Traffic Usage System alarm handling - Gateway, RadiusGWProxy,RadiusProxy Server.docx

    sftp: sent 21.2 KB in 0.01seconds

    #在弹出的Windows框中选择文件上传 注意上传路径与当前路径要相同 

    sftp:/mnt/share> put

    Uploading VirtualBrowser.docx to remote:/mnt/share/Virtual Browser.docx

    sftp: sent 14.4 KB in 0.02seconds

    sftp:/mnt/share> put

    Uploading CheckPlan--Jacky.docx to remote:/mnt/share/Check Plan--Jacky.docx

    sftp: sent 453 KB in 0.05seconds

    sftp:/mnt/share> put

    Uploading ZMMSC.docx toremote:/mnt/share/ZMMSC.docx

    sftp: sent 22.0 KB in 0.00seconds

    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:270.jpg

    -rwxrwxrwx   1 1000    users      16157 Jun 16 13:39Auth Server and SOAP proxy.docx

    -rwxrwxrwx   1 1000    users      63952 Jun 16 12:29bamquickinstall.pdf

    -rwxrwxrwx   1 1000    users     464191 Jun 16 13:53Check Plan--Jacky.docx

    -rwxrwxrwx   1 1000    users       7277 Jun 16 13:33DNSmmmS.txt

    -rwxrwxrwx   1 1000    users       7277 May 12 10:43DNSS.txt

    -rwxrwxrwx   1 1000    users     111395 Jun 15 15:46libpcap-0.9.4-15.el5.x86_64.rpm

    -rwxrwxrwx   1 1000    users     363677 Jun 15 14:59ppp-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:38pptpd-1.4.0-1.rhel4.x86_64.rpm

    -rwxrwxrwx   1 1000    users      86509 Jun 15 14:46pptpd-1.4.0-1.rhel5.x86_64.rpm

    -rwxrwxrwx   1 1000    users     220151 Jun 15 13:22Screenshot.png

    -rwxrwxrwx   1 1000    users      21789 Jun 16 13:52Traffic Usage System alarm handling - Gateway, RadiusGWProxy, RadiusProxyServer.docx

    -rwxrwxrwx   1 1000    users      14815 Jun 16 13:53Virtual Browser.docx

    -rwxrwxrwx   11000    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

    #查看是否创建成功

    Remotedirectory is /mnt/share/test

    sftp:/mnt/share/test> cd /mnt/share/

    sftp:/mnt/share> rmdir /test

    cannotremove /test: no such a directory

    sftp:/mnt/share>rmdir /mnt/share/test

    #删除刚创建的目录/mnt/share/test

    sftp:/mnt/share> cd /mnt/share/test

    cannotchange to /mnt/share/test: no such a directory

    #确认是否删除成功

     

    实例4、在远程服务器删除文件

    sftp:/mnt/share> rm ./ZMMSC

    #删除远程服务器/mnt/share上的文件ZMMSC.docx./表示当前目录

    cannotdelete /mnt/share/./ZMMSC: no such a file

    sftp:/mnt/share> rm ./ZMMSC.docx

    deleted/mnt/share/./ZMMSC.docx

    sftp:/mnt/share> rm ./Traffic UsageSystem 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:270.jpg

    -rwxrwxrwx   1 1000    users      16157 Jun 16 13:39 AuthServer and SOAP proxy.docx

    -rwxrwxrwx   1 1000    users      63952 Jun 16 12:29bamquickinstall.pdf

    -rwxrwxrwx   1 1000    users     464191 Jun 16 13:53Check Plan--Jacky.docx

    -rwxrwxrwx   1 1000    users       7277 Jun 16 13:33DNSmmmS.txt

    -rwxrwxrwx   1 1000    users     111395 Jun 15 15:46libpcap-0.9.4-15.el5.x86_64.rpm

    -rwxrwxrwx   1 1000    users     363677 Jun 15 14:59ppp-2.4.4-14.1.rhel5.x86_64.rpm

    -rwxrwxrwx   1 1000    users      48430 Jun 15 14:57ppp-devel-2.4.4-14.1.rhel5.x86_64.rpm

    -rwxrwxrwx   1 1000    users      86211 Jun 15 15:38pptpd-1.4.0-1.rhel4.x86_64.rpm

    -rwxrwxrwx   1 1000    users      86509 Jun 15 14:46pptpd-1.4.0-1.rhel5.x86_64.rpm

    -rwxrwxrwx   1 1000    users     220151 Jun 15 13:22Screenshot.png

    -rwxrwxrwx   1 1000    users      21789 Jun 16 13:52Traffic Usage System alarm handling - Gateway, RadiusGWProxy, RadiusProxyServer.docx

    -rwxrwxrwx   1 1000    users      14815 Jun 16 13:53Virtual Browser.docx

    sftp:/mnt/share>

  • 相关阅读:
    【转】微信小程序原理
    【转】onAttachedToWindow()在整个Activity生命周期的位置及使用
    中序遍历非递归遍历算法
    多项式加法运算
    中缀表达式转换为后缀表达式
    多项式计算
    最大子列和问题
    广度优先搜索
    广搜和深搜的区别
    cookie 与 session 的区别详解
  • 原文地址:https://www.cnblogs.com/vincentcheng/p/7653648.html
Copyright © 2020-2023  润新知