当前位置: 首页 > 工具软件 > Sublime AFTP > 使用案例 >

Sublime Text 如何连接 FTP/SFTP

葛念
2023-12-01
默认的sublime text是没有这个sftp连接功能的,这只是一个文本编辑器,相当于windows下的txt,所以要先装上插件:
1) 安装package control组件:
按Ctrl+`调出console, 粘贴以下代码到底部命令行并回车:
import urllib2,os;pf='Package Control.sublime-package';ipp=sublime.installed_packages_path();os.makedirs(ipp) if not os.path.exists(ipp) else None;open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read())
如果是Sublime Text 3执行上述代码会报错,改成如下即可:
import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())


2)重启Sublime Text。

如果在Perferences->package settings中看到package control这一项,则安装成功。


3)用Package Control安装sftp插件的方法:

按下Ctrl+Shift+P调出命令面板
输入install 调出 Install Package 选项并回车,然后输入ftp,下拉列表中会出现一些相关的插件,选中sftp进行安装就行了。


4) 对于某项目下的文件上传配置,可按如下配置操作:

右键项目-> SFTP/FTP -> Map to Remote .点击Map to Remote,看到配置文件。编辑完成后保存,在项目目录下可看到多了一个文件sftp-config.json。
普通的ftp连接修改下列配置:
{
    // 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": "ftp",


    "save_before_upload": true,
    "upload_on_save": true,
    "sync_down_on_open": false,
    "sync_skip_deletes": true,
    "sync_same_age": true,
    "confirm_downloads": false,
    "confirm_sync": true,
    "confirm_overwrite_newer": false,
    
    "host": "192.168.0.115",
    "user": "ftptest",
    "password": "ftptest",
    "port": "21",
    
    "remote_path": "/data/service",
    "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" ,
        "\\.svn"
    ],
    //"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,
}








{
    // 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": true,
    "sync_down_on_open": false,
    "sync_skip_deletes": true,
    "sync_same_age": true,
    "confirm_downloads": false,
    "confirm_sync": true,
    "confirm_overwrite_newer": false,
    
    "host": "192.168.0.115",
    "user": "root",
    "password": "220",
    "port": "22",
    
    "remote_path": "/data/service/src_new",
    "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" ,
        "\\.svn"
    ],
    //"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/FTP , 在这里就可以进行一系列操作了,具体操作菜单写的很清楚了。
 类似资料: