⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 java实现ftp下载文件 .txt

📁 windows下的编程 一共有7篇!
💻 TXT
字号:
 
java实现ftp下载文件 
版权声明:CSDN是本Blog托管服务提供商。如本文牵涉版权问题,CSDN不承担相关责任,请版权拥有者直接与文章作者联系解决。



比如要下载ftp://ftp.xx.com/index.html则:

import sun.net.ftp.FtpClient;
import java.io.*;
import sun.net.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author  petehero
 * @version 1.0
 */

public class ftpDown
{

    public ftpDown()
    {

    }
    public static void main(String[] args)
    {
        try
        {
            FtpClient fc=new FtpClient("ftp.xx.com");
            fc.login("username","888888");
            int ch;
            File fi = new File("c:\\index.html");
            RandomAccessFile getFile = new RandomAccessFile(fi,"rw");
            getFile.seek(0);
            TelnetInputStream fget=fc.get("index.html");
            DataInputStream puts = new DataInputStream(fget);
            while ((ch = puts.read()) >= 0) {
                getFile.write(ch);
            }
            fget.close();
            getFile.close();
            fc.closeServer();
        }
        catch (IOException ex)
        {

            ex.printStackTrace();
        }

    }
}

 

如果文件在某个目录下,则加入fc.cd("foodir");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -