使用SecureCRT的SFTP在WINDOWS與LINUX之間傳輸檔案

來源:互聯網
上載者:User

標籤:

背景:  有一台主機,安裝了windows7,在其安裝了virtualbox,然後安裝了ubuntu虛擬機器。在windows7上安裝SecureCRT來ssh串連ubuntu虛擬機器。一般在windows上面下載軟體,然後通過vsftp上傳到ubuntu虛擬機器上。但是這樣非常麻煩,現在考慮使用sftp協議來直接傳輸。方案:  使用SecureCRT軟體ssh串連到ubuntu虛擬機器。然後在SecureCRT上面開啟SFTP會話,可以按 ALT + p 按鍵組合如所示:   SFTP命令  進入到sftp命令視窗以後,就可以通過sftp命令來進行檔案互傳的操作。下面主要介紹一下sftp命令的含義。
sftp> helpAvailable commands:ascii                          Set transfer mode to ASCIIbinary                         Set transfer mode to binarycd path                        Change remote directory to ‘path‘lcd path                       Change local directory to ‘path‘detail remote-path             Display system information about remote                                 file or folderldetail local-path             Display system information about local                                 file or folderchgrp group path               Change group of file ‘path‘ to ‘group‘chmod mode path                Change permissions of file ‘path‘ to ‘mode‘chown owner path               Change owner of file ‘path‘ to ‘owner‘exit                           Quit sftphelp                           Display this help textinclude filename               Include commands from ‘filename‘                                 Alternate: < filenameget [-r][-a | -b] remote-path  Download file                                 -r downloads directory recursively                                 force ascii (-a) or binary (-b) modeln [-s] existingpath linkpath  Hardlink / symlink remote filels [options] [path]            Display remote directory listinglls [options] [path]           Display local directory listingmkdir path                     Create remote directorylmkdir path                    Create local directorymv oldpath newpath             Move remote filelmv oldpath newpath            Move local fileopen [[email protected]]host[:port]        Connect to remote hostput [-r][-a | -b] local-path   Upload file                                 -r uploads directory recursively                                 force ascii (-a) or binary (-b) modepwd                            Display remote working directorylpwd                           Print local working directoryquit                           Quit sftprename oldname newname         Rename remote filelrename oldname newname        Rename local filermdir path                     Remove remote directorylrmdir path                    Remove local directoryrm path                        Delete remote filelrm path                       Delete local filesu username                    Substitutes the current user                                 This is only supported with VShell for                                  Windows 3.5 or later.type [transfer-mode]           Display or set file transfer modeview remote-path               Download and open fileversion                        Display protocol version

翻譯一下就是:

sftp-- help 可用命令: cd 路徑                        更改遠程目錄到“路徑” lcd 路徑                       更改本地目錄到“路徑” chgrp group path               將檔案“path”的組更改為“group” chmod mode path                將檔案“path”的許可權更改為“mode” chown owner path               將檔案“path”的屬主更改為“owner” exit                           退出 sftp help                           顯示這個協助文本 get 遠程路徑                   下載檔案 ln existingpath linkpath       符號連結遠程檔案 ls [選項] [路徑]               顯示遠程目錄列表 lls [選項] [路徑]              顯示本地目錄列表 mkdir 路徑                     建立遠程目錄 lmkdir 路徑                    建立本地目錄 mv oldpath newpath             移動遠程檔案 open [使用者@]主機[:連接埠]        串連到遠程主機 put 本地路徑                   上傳檔案 pwd                            顯示遠程工作目錄 lpwd                           列印本地工作目錄 quit                           退出 sftp rmdir 路徑                     移除遠程目錄 lrmdir 路徑                    移除本地目錄 rm 路徑                        刪除遠程檔案 lrm 路徑                       刪除本地檔案 symlink existingpath linkpath  符號連結遠程檔案 version                        顯示協議版本 

我們主要用到的就是一下六個命令

cd 路徑                        更改遠程目錄到“路徑” lcd 路徑                       更改本地目錄到“路徑” ls [選項] [路徑]               顯示遠程目錄列表 lls [選項] [路徑]              顯示本地目錄列表 put 本地路徑                   上傳檔案 get 遠程路徑                   下載檔案 

這裡在詳細說明一下遠程目錄本地目錄

遠程目錄:ls查看到的是ubuntu虛擬機器上面的目錄

本地目錄:lls查看到的是windows實體機上面的目錄。

執行個體:

假設我需要實現windows下的e:\sftp\test1.txt和ubuntu下/home/enadmin/test2.txt的互換,可以進行一下操作:

put操作:windows->linux

查看目錄許可權

[email protected]:/home# lltotal 20drwxr-xr-x  5 root    root    4096 Apr 18 15:21 ./drwxr-xr-x 24 root    root    4096 Jan  3 14:14 ../drwxr-xr-x  9 enadmin enadmin 4096 Apr 18 15:22 enadmin/drwxr-xr-x  2 root    root    4096 Apr 18 15:21 sftp/--可以看到sftp的許可權是root的drwxr-xr-x  2 root    root    4096 Apr 18 14:57 test/[email protected]:/home# chown -R enadmin.enadmin sftp/[email protected]:/home# lltotal 20drwxr-xr-x  5 root    root    4096 Apr 18 15:21 ./drwxr-xr-x 24 root    root    4096 Jan  3 14:14 ../drwxr-xr-x  9 enadmin enadmin 4096 Apr 18 15:22 enadmin/drwxr-xr-x  2 enadmin enadmin 4096 Apr 18 15:21 sftp/--修改以後許可權變成enadmin的了drwxr-xr-x  2 root    root    4096 Apr 18 14:57 test/

拷貝檔案

sftp> put test* --初始想將檔案從windows系統put到ubuntu系統,發現失敗,提示拒絕訪問Uploading test1.txt to /home/test1.txtput: failed to upload e:/sftp/test1.txt. 拒絕訪問。 Uploading test2.txt to /home/test2.txtput: failed to upload e:/sftp/test2.txt. 拒絕訪問。 Uploading test3.txt to /home/test3.txtput: failed to upload e:/sftp/test3.txt. 拒絕訪問。 sftp> pwd --查看目前的目錄是/home目錄,許可權是root的/homesftp> cd /home/enadmin/ --我切換到enadmin目錄下sftp> lsGraphs.pm             msmtp                 ntpsent                  smokeping.tar.gz      smokepingrtt.tar.gzsmokepingrtt2.tar.gz  Target                wqywqy-zenhei-0.8.38-1.debsftp> llstest1.txt             test2.txt             test3.txtsftp> put test* -再次嘗試將windows下的檔案put到/homg/enadmin目錄下,這次成功Uploading test1.txt to /home/enadmin/test1.txt  100% 4 bytes      4 bytes/s 00:00:00     e:/sftp/test1.txt: 4 bytes transferred in 0 seconds (4 bytes/s)Uploading test2.txt to /home/enadmin/test2.txt  100% 4 bytes      4 bytes/s 00:00:00     e:/sftp/test2.txt: 4 bytes transferred in 0 seconds (4 bytes/s)Uploading test3.txt to /home/enadmin/test3.txt  100% 5 bytes      5 bytes/s 00:00:00     e:/sftp/test3.txt: 5 bytes transferred in 0 seconds (5 bytes/s)sftp> cd /home/sftp/--在修改sftp目錄許可權以後,再次切換到sftp目錄下sftp> lssftp> llstest1.txt             test2.txt             test3.txtsftp> put test* --這回put成功。所以跟許可權相關Uploading test1.txt to /home/sftp/test1.txt  100% 4 bytes      4 bytes/s 00:00:00     e:/sftp/test1.txt: 4 bytes transferred in 0 seconds (4 bytes/s)Uploading test2.txt to /home/sftp/test2.txt  100% 4 bytes      4 bytes/s 00:00:00     e:/sftp/test2.txt: 4 bytes transferred in 0 seconds (4 bytes/s)Uploading test3.txt to /home/sftp/test3.txt  100% 5 bytes      5 bytes/s 00:00:00     e:/sftp/test3.txt: 5 bytes transferred in 0 seconds (5 bytes/s)

注意點:這裡需要注意許可權的問題。加入我是使用enadmin賬戶初始串連ubuntu的,那麼我put的檔案只能放到檔案夾許可權是enadmin的目錄下,不能放到檔案夾許可權是root的目錄下。如果想放到檔案夾許可權是root的目錄下,那麼初始就使用root賬戶串連ubunut,然後再建立sftp會話,這樣就可以了。

get操作:linux->windows

get操作沒有許可權設定

sftp> pwd/home/enadminsftp> lpwde:/Documentssftp> lcd e:/sftp --切換目錄sftp> llsrc.local              test1.txt             test2.txttest3.txtsftp> lsGraphs.pm             msmtp                 ntpsent                  smokeping.tar.gz      smokepingrtt.tar.gzsmokepingrtt2.tar.gz  Target                test1.txttest2.txt             test3.txt             wqywqy-zenhei-0.8.38-1.debsftp> get Graphs.pm --下載檔案到windowsDownloading Graphs.pm from /home/enadmin/Graphs.pm  100% 13KB     13KB/s 00:00:00     /home/enadmin/Graphs.pm: 13503 bytes transferred in 0 seconds (13 KB/s)sftp> lls --查看windows目錄Graphs.pm             rc.local              test1.txttest2.txt             test3.txtsftp> 

 

在window下向linux傳送檔案的方法。

首先在window中安裝SecureCRT,然後在快速串連中建立一個到linux的串連,當然,你要Crowdsourced Security Testing道你的系統的ip,在終端中鍵入ifconfig可以查看到。

然後串連即可登陸到linux的終端下

要從linux傳檔案到window的話,這需要cd到你要傳的檔案的目錄,然後用命令:sz 檔案名稱即可上傳。檔案放在securesrt/download下面

要從window傳送檔案到linux,則在終端中輸入rz,然後會出來一個對話方塊讓你選擇檔案傳送的。

一般來說,linux伺服器大多是通過ssh用戶端來進行遠端登陸和管理的,使用ssh登陸linux主機以後,如何能夠快速的和本地機器進行檔案的互動呢,也就是上傳和下載檔案到伺服器和本地;

與ssh有關的兩個命令可以提供很方便的操作:

sz:將選定的檔案發送(send)到本地機器

rz:運行該命令會彈出一個檔案選擇視窗,從本地選擇檔案上傳到伺服器(receive)

rz,sz是便是Linux/Unix同Windows進行ZModem檔案傳輸的命令列工具

windows端需要支援ZModem的telnet/ssh用戶端(比如SecureCRT)

運行命令rz,即是接收檔案,SecureCRT就會彈出檔案選擇對話方塊,選好檔案之後關閉對話方塊,檔案就會上傳到目前的目錄

注意:單獨用rz會有兩個問題:上傳中斷、上傳檔案變化(md5不同),解決辦法是上傳是用rz -be,並且去掉彈出的對話方塊中“Upload files as ASCII”前的勾選。

-b binary 用binary的方式上傳下載,不解釋字元為ascii

-e 強制escape 所有控制字元,比如Ctrl+x,DEL等

運行命令sz file1 file2就是發檔案到windows上(儲存的目錄是可以配置) 比ftp命令方便多了,而且伺服器不用再開FTP服務了

PS:Linux上rz/sz這兩個小工具安裝lrzsz-x.x.xx.rpm即可。

當然,還可以設定一下目錄了:

設定一下上傳和下載的預設目錄

options–>session options–>file transfer 下可以設定上傳和下載的目錄

剩下的你只要在用SecureCRT登陸linux終端的時候:

傳送檔案到用戶端:sz filename

zmodem接收可以自行啟動.

從用戶端上傳檔案到linux服務端:

只要服務端執行 : rz

然後在 SecureCRT 裡選檔案發送,協議 zmodem

附:yum 根據命令名反查安裝包用法

比如查 rz 命令的安裝包名稱

yum  whatprovides */rz

使用SecureCRT的SFTP在WINDOWS與LINUX之間傳輸檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.