win设置ftp服务器~java通过ftp下载文件

作者 : admin 本文共749个字,预计阅读时间需要2分钟 发布时间: 2024-06-10 共3人阅读

1.先设置ftp

win设置ftp服务器~java通过ftp下载文件插图

2.打开服务

win设置ftp服务器~java通过ftp下载文件插图(1)

3.设置站点

win设置ftp服务器~java通过ftp下载文件插图(2)

4.起名字

win设置ftp服务器~java通过ftp下载文件插图(3)

win设置ftp服务器~java通过ftp下载文件插图(4)

这样就可以了

5.剩下的就是设置权限和账号了,找到对应的按钮就可以了

6.下载文件的代码

  


    public byte[] downloadFile(File file) throws IOException{
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        toDir(file.getParent());
        client.retrieveFile(new String(file.getName().getBytes(),"ISO-8859-1"), out);
        byte[] data = out.toByteArray();
        if(data.length == 0){
            throw new IOException("ftp文件未找到");
        }
        out.close();
        return data;
    }

    public class MtFtp {

    public static void main(String[] args) throws Exception {
        ApacheFtpClient client = new ApacheFtpClient("10.10.10.10", 21, true);
        client.login("ftp","bai123456");
        client.setting();
        client.dirRoot();
        byte[] data = client.downloadFile(new File("/a/b/c/test.pdf"));
        FileOutputStream oo = new FileOutputStream("D:/imgTest/测试.pdf");
        oo.write(data);
        oo.flush();
        oo.close();

    }
}

ftp的其他操作可以搜我之前的帖子
本站无任何商业行为
个人在线分享 » win设置ftp服务器~java通过ftp下载文件
E-->