Logo Search packages:      
Sourcecode: jftp version File versions  Download package

int net::sf::jftp::net::FtpConnection::rawUpload ( String  file,
String  realName,
InputStream  in 
) [inline, private]

uploads a file

Definition at line 1641 of file FtpConnection.java.

References net::sf::jftp::net::DataConnection::finished, getLine(), getLocalPath(), host, net::sf::jftp::net::DataConnection::isThere, jcon, list(), modeStream(), pause(), net::sf::jftp::net::FtpConstants::REST, net::sf::jftp::net::JConnection::send(), sortLs(), sortSize(), net::sf::jftp::net::FtpConstants::STOR, net::sf::jftp::net::FtpConstants::TRANSFER_FAILED, and net::sf::jftp::net::FtpConstants::TRANSFER_SUCCESSFUL.

    {
        if(!file.equals(realName))
        {
            Log.debug("File: " + file + ", stored as " + realName);
        }
        else
        {
            Log.debug("File: " + file);
            realName = null;
        }

        file = parse(file);

        String path = file;

        try
        {
            int p = 0;

            if(StringUtils.isRelative(file))
            {
                path = getLocalPath() + file;
            }

            file = StringUtils.getFile(file);

            //BufferedReader in = jcon.getReader();
            boolean resume = false;
            String size = "0";

            if(Settings.enableUploadResuming && (in == null))
            {
                list();

                String[] ls = sortLs();
                String[] sizes = sortSize();

                if((ls == null) || (sizes == null))
                {
                    Log.out(">>> ls out of sync (skipping resume check)");
                }
                else
                {
                    for(int i = 0; i < ls.length; i++)
                    {
                        //Log.out(ls[i] + ":" + sizes[i]);
                        if(realName != null)
                        {
                            if(ls[i].equals(realName))
                            {
                                resume = true;
                                size = sizes[i];

                                break;
                            }
                        }
                        else
                        {
                            if(ls[i].equals(file))
                            {
                                resume = true;
                                size = sizes[i];
                            }
                        }
                    }

                    File f = new File(path);

                    if(f.exists() && (f.length() <= Integer.parseInt(size)))
                    {
                        Log.out("skipping resuming, file is <= filelength");
                        resume = false;
                    }
                    else if(f.exists() && Integer.parseInt(size) > 0)
                    {
                        if(!Settings.noUploadResumingQuestion) {
                              if(JOptionPane.showConfirmDialog(new JLabel(), "A file smaller than the one to be uploaded already exists on the server,\n do you want to resume the upload?", "Resume upload?", JOptionPane.YES_NO_OPTION)
                                          != JOptionPane.OK_OPTION) {
                                    resume = false;
                              }
                        }
                        Log.out("resume: " + resume + ", size: " + size);
                    }
                    else {
                        Log.out("resume: " + resume + ", size: " + size);
                    }
                }
            }

            modeStream();

            //binary();
            p = negotiatePort();

            if(resume && Settings.enableUploadResuming)
            {
                jcon.send(REST + " " + size);

                if(getLine(PROCEED) == null)
                {
                    resume = false;
                }
            }

            dcon = new DataConnection(this, p, host, path, dataType, resume,
                                      Integer.parseInt(size), in); //, new Updater());

            while(!dcon.isThere())
            {
                pause(10);
            }

            //System.out.println(path + " : " + file);
            if(realName != null)
            {
                jcon.send(STOR + " " + realName);
            }
            else
            {
                jcon.send(STOR + " " + file);
            }

            String tmp = getLine(POSITIVE);

            if(!tmp.startsWith(POSITIVE) && !tmp.startsWith(PROCEED))
            {
                return TRANSFER_FAILED;
            }

            Log.debug(tmp);

            // we need to block since some ftp-servers do not want the
            // refresh command that dirpanel sends otherwise
            while(!dcon.finished)
            {
                pause(10);
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            Log.debug(ex.toString() + " @FtpConnection::upload");

            return TRANSFER_FAILED;
        }

        return TRANSFER_SUCCESSFUL;
    }


Generated by  Doxygen 1.6.0   Back to index