vscode使用ftp-sync快速上传项目代码到服务器(宝塔ftp为例)

使用vscode开发工具小伙伴们可以在vscode搜一下ftp-sync这个插件,然后点击下载安装
在这里插入图片描述
2.使用快捷键 Ctrl+Shift+P命令,输入ftp-sync:Init 然后选中执行
在这里插入图片描述
3.执行上述命令快速生成.vscode/ftp-svnc.json文件,里面是一些配置信息
在这里插入图片描述
ftp-sync.json内容

{
    "remotePath": "/", // 这个是基于宝塔生成的目录
    "host": "117.78.44.57", // 这个是自己服务器ip
    "username": "ftpsynctest", // 宝塔ftp的账户名
    "password": "12345678", // 宝塔ftp的密码
    "port": 21, // 默认端口21 
    "secure": false,
    "protocol": "ftp",
    "uploadOnSave": false,
    "passive": false,
    "debug": false,
    "privateKeyPath": null,
    "passphrase": null,
    "agent": null,
    "allow": [],
    "ignore": [
        "\\.vscode",
        "\\.git",
        "\\.DS_Store"
    ],
    "generatedFiles": {
        "extensionsToInclude": [
            ""
        ],
        "path": ""
    }
}

此处宝塔随便建一个测试ftp,点击添加FTP,然后基于服务器根目录/www/wwwroot/ftpsynctest,这里的ftpsynctest是自己项目名称。上面ftp-sync的remotePath配置其实就是基于/www/wwwroot/ftpsynctest这个根目录,上传之后项目实际路径就是/www/wwwroot/ftpsynctest/项目源码
在这里插入图片描述
比如我现在要上传静态index.html,操作只需要右击index.html,选中ftp-sync:upload File指令即可,成功的话直接在宝塔/www/wwwroot/ftpsynctest/这个路径下就能看到index.html。失败的话,可以查查对应报错方式,许多博客都有处理方案。
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,关于这个问题,以下是一个简单的示例代码: ``` import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; import java.net.UnknownHostException; public class FTPUploader { public static void main(String[] args) { String server = "yourFTPserver.com"; int port = 21; String username = "yourUsername"; String password = "yourPassword"; String filePath = "/path/to/your/file.txt"; String remoteDirPath = "/remote/directory/path/"; try { Socket socket = new Socket(server, port); InputStream inputStream = socket.getInputStream(); OutputStream outputStream = socket.getOutputStream(); login(username, password, inputStream, outputStream); sendCommand("CWD " + remoteDirPath, inputStream, outputStream); sendCommand("TYPE I", inputStream, outputStream); File file = new File(filePath); FileInputStream fileInputStream = new FileInputStream(file); sendCommand("STOR " + file.getName(), inputStream, outputStream); byte[] buffer = new byte[4096]; int bytesRead = 0; while ((bytesRead = fileInputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } fileInputStream.close(); outputStream.close(); inputStream.close(); socket.close(); System.out.println("File transfer complete!"); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private static void login(String username, String password, InputStream inputStream, OutputStream outputStream) throws IOException { sendCommand("USER " + username, inputStream, outputStream); sendCommand("PASS " + password, inputStream, outputStream); } private static void sendCommand(String command, InputStream inputStream, OutputStream outputStream) throws IOException { outputStream.write((command + "\r\n").getBytes()); String response = readResponse(inputStream); System.out.println("> " + command); System.out.println("< " + response); } private static String readResponse(InputStream inputStream) throws IOException { byte[] buffer = new byte[4096]; int bytesRead = inputStream.read(buffer); return new String(buffer, 0, bytesRead); } } ``` 这是一个基本的FTP上传文件的Java代码,需要根据你的具体情况进行修改。这段代码使用Socket连接FTP服务器,登录验证后进入指定的远程目录,将本地文件上传服务器

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

追逐梦想之路_随笔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值