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

📄 downloadqueue.java

📁 一个JAVA做的FTP软件,带源码的,可以很好的进行二次开发,,并带有详细说明文件的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            }            FileOutputStream fos;            PrintStream f = new PrintStream((fos = new FileOutputStream(file)));            for(int i = 0; i <= queue.size(); i++)            {                QueueRecord rec = (QueueRecord) queue.get(i);                f.println(rec.type);                f.println(rec.hostname);                f.println(rec.username);                f.println(rec.password);                f.println(rec.port);                f.println(rec.file);                f.println(rec.local);                f.println(rec.remote);                f.println(rec.localip);                f.println(rec.domain);            }            fos.close();        }        catch(Exception ex)        {            ex.printStackTrace();        }    }    private void loadList(File file)    {        try        {            BufferedReader breader = new BufferedReader(new FileReader(file));            boolean Eof = false;            queue.clear();            liststr.clear();            while(!Eof)            {                QueueRecord rec = new QueueRecord();                rec.type = breader.readLine();                rec.hostname = breader.readLine();                rec.username = breader.readLine();                rec.password = breader.readLine();                rec.port = breader.readLine();                rec.file = breader.readLine();                rec.local = breader.readLine();                rec.remote = breader.readLine();                rec.localip = breader.readLine();                rec.domain = breader.readLine();                if(rec.hostname == null)                {                    Eof = true;                }                else                {                    queue.add(rec);                    liststr.addElement(rec.hostname + " : " + rec.remote +                                       rec.file);                }            }        }        catch(Exception ex)        {        }    }    // ------------ needed by Logger interface  --------------    // main log method    public void debug(String msg)    {        System.out.println(msg);    }    // rarely used    public void debugRaw(String msg)    {        System.out.print(msg);    }    // methods below are not used yet.    public void debug(String msg, Throwable throwable)    {    }    public void warn(String msg)    {    }    public void warn(String msg, Throwable throwable)    {    }    public void error(String msg)    {    }    public void error(String msg, Throwable throwable)    {    }    public void info(String msg)    {    }    public void info(String msg, Throwable throwable)    {    }    public void fatal(String msg)    {    }    public void fatal(String msg, Throwable throwable)    {    }    class QueueRecord    {        public String type;        // parameter used for ftp        public String hostname;        public String username;        public String password;        public String port;        public String file;        // local path        public String local;        // remote path        public String remote;        // used only for smb        public String localip;        public String domain;        public QueueRecord()        {        }    }    class queueDownloader extends Thread implements ConnectionListener    {        public boolean block = false;        public boolean connected = false;        public QueueRecord last;        private FtpConnection conFtp;        public void run()        {            try            {                while((queue.size() >= 1) && !block)                {                    QueueRecord rec = (QueueRecord) queue.get(0);                    last = rec;                    if(!connected)                    {                        con = new FtpConnection(rec.hostname,                                                Integer.parseInt(rec.port), "/");                        conFtp = (FtpConnection) con;                        conFtp.addConnectionListener(this);                        conFtp.setConnectionHandler(handler);                        conFtp.login(rec.username, rec.password);                        connected = true;                    }                    conFtp.chdirNoRefresh(rec.remote);                    conFtp.setLocalPath(rec.local);                    int i = 0;                    while(!isThere)                    {                        i++;                        if(i > NumRetry)                        {                            return;                        }                        try                        {                            Thread.sleep(10);                        }                        catch(Exception ex)                        {                            ex.printStackTrace();                        }                    }                    conFtp.download(rec.file);                    statuslabel.setText("");                    if(queue.size() >= 1)                    {                        rec = (QueueRecord) queue.get(0);                        if((rec.hostname.compareTo(last.hostname) == 0) &&                               (rec.port.compareTo(last.port) == 0) &&                               (rec.username.compareTo(last.username) == 0) &&                               (rec.password.compareTo(last.password) == 0))                        {                            connected = true;                        }                        else                        {                            conFtp.disconnect();                            connected = false;                        }                    }                    else                    {                        conFtp.disconnect();                        connected = false;                    }                    Thread.sleep(100);                }            }            catch(InterruptedException e)            {            }            if(connected)            {                con.disconnect();            }        }        // ------------------ needed by ConnectionListener interface -----------------        // called if the remote directory has changed        public void updateRemoteDirectory(BasicConnection con)        {        }        // called if a connection has been established        public void connectionInitialized(BasicConnection con)        {            isThere = true;        }        // called every few kb by DataConnection during the trnsfer (interval can be changed in Settings)        public void updateProgress(String file, String type, long bytes)        {            String strtmp;            if(StringUtils.getFile(file).compareTo("") == 0)            {                strtmp = "directory " + file;            }            else            {                strtmp = "file " + StringUtils.getFile(file);            }            statuslabel.setText("Downloading " + strtmp + " - kbyte " +                                (bytes / 1024));            String tmp;            if(type.length() >= 10)            {                tmp = type.substring(0, 9);            }            else            {                tmp = " ";            }            if(((type.compareTo(DataConnection.FINISHED) == 0) ||                   (tmp.compareTo(DataConnection.DFINISHED) == 0)) && !block)            {                queue.remove(0);                liststr.remove(0);            }        }        // called if connection fails        public void connectionFailed(BasicConnection con, String why)        {            System.out.println("connection failed!");        }        // up- or download has finished        public void actionFinished(BasicConnection con)        {        }    }}

⌨️ 快捷键说明

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