Sublime Text編輯遠程Linux服務器上的文件


sublime有個叫sftp的插件,可以通過它直接打開遠程機器上的文件進行編輯,並在保存后直接同步到遠程linux服務器上。

用Package Control安裝插件

按下Ctrl+Shift+P調出命令面板

輸入install 調出 Install Package 選項並回車,然后輸入FTP,下拉列表中會出現一些相關的插件,

選中SFTP進行安裝就行了,裝好后還需配置如下:選菜單欄中的File->SFTP/FTP->Setup Server,然后

出現一個配置窗口如下:

{ // The tab key will cycle through the settings when first created // Visit http://wbond.net/sublime_packages/sftp/settings for help // sftp, ftp or ftps
    "type": "sftp",

    "sync_down_on_open": true,
    "sync_same_age": true,
     
    "host": "example.com",             //遠程服務器的地址IP 123.234.345.456
    "user": "username",                //root //"password": "password", //密碼可以不保存,在輸入完地址和用戶的時候回車輸入 //"port": "22",
    
    "remote_path": "/example/path/",   //要進入的目錄 比如 /data/www/ //"file_permissions": "664", //"dir_permissions": "775", //"extra_list_connections": 0,

    "connect_timeout": 30,
    //"keepalive": 120, //"ftp_passive_mode": true, //"ftp_obey_passive_host": false, //"ssh_key_file": "~/.ssh/id_rsa", //"sftp_flags": ["-F", "/path/to/ssh_config"], //"preserve_modification_times": false, //"remote_time_offset_in_hours": 0, //"remote_encoding": "utf-8", //"remote_locale": "C", //"allow_config_upload": false,
}

配置完成之后保存到默認的目錄 :D:\Sublime Text3\Data\Packages\User\sftp_servers ,文件名自己取,如果配置多個服務器的話,比較容易區分,比如 host1Config.txt

如果配置了多個,下次在打算編輯其中某台服務器上的文件時,就可以File->SFTP/FTP->Browse Server,選擇目標文件即可 

 

如果你想講linux上的一個完整的目錄拉倒sublime里面,就如同打開windows本地的文件一樣,需要進行如下操作:

第一步:先在本地創建一個文件夾,用sublime打開

第二步:右鍵左側sidbar中這個文件圖標,選擇SFTP/FTP: SFTP > Map to Remote…

第三步:在彈出的配置文件(如上)中修改相應的配置,ssh的ip,用戶名,密碼,想要打開的目錄,(如上次的方法)

{ // The tab key will cycle through the settings when first created // Visit http://wbond.net/sublime_packages/sftp/settings for help // sftp, ftp or ftps
    "type": "sftp",

    "save_before_upload": true,
    "upload_on_save": false,
    "sync_down_on_open": false,
    "sync_skip_deletes": false,
    "sync_same_age": true,
    "confirm_downloads": false,
    "confirm_sync": true,
    "confirm_overwrite_newer": false,
    
    "host": "123.234.345.456",        //IP
    "user": "root",                   //root
    "password": "Guos...",            //password //"port": "22",
    
    "remote_path": "/data/www/b....", //目錄文件夾路徑
    "ignore_regexes": [ "\\.sublime-(project|workspace)", "sftp-config(-alt\\d?)?\\.json",
        "sftp-settings\\.json", "/venv/", "\\.svn/", "\\.hg/", "\\.git/",
        "\\.bzr", "_darcs", "CVS", "\\.DS_Store", "Thumbs\\.db", "desktop\\.ini" ],
    //"file_permissions": "664", //"dir_permissions": "775", //"extra_list_connections": 0,

    "connect_timeout": 30,
    //"keepalive": 120, //"ftp_passive_mode": true, //"ftp_obey_passive_host": false, //"ssh_key_file": "~/.ssh/id_rsa", //"sftp_flags": ["-F", "/path/to/ssh_config"], //"preserve_modification_times": false, //"remote_time_offset_in_hours": 0, //"remote_encoding": "utf-8", //"remote_locale": "C", //"allow_config_upload": false,
}

第三步:右鍵文件圖標,SFTP > Download Folder,然后等待同步完成

(如果出錯,可能是編碼的問題,忽略掉編碼不正確的文件,或者修改編碼)

更改完你的操作后,你可以通過右鍵目錄名,點擊SFTP/FTP: Upload Folder >,即可同步到linux服務器上。 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM