It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Java Forum

Download multiple files from ftp

Download multiple files from ftp

Postby Satanduvel on Mon Apr 23, 2007 11:55 am

Hi everybody i'm back. My problem is now I can download 1 file but when i'm selecting 2 rows and want to download the files i get this error: java.lang.NullPointerException. Here are some lines i got by the System out.println lines.

Lines i get for downloading 1file:

Code: Select all
max1
Value:1.jpg
Root:/web/../..
/web/../../1.jpg
Directory:/web/../..
In:org.apache.commons.net.io.SocketInputStream@ee3aa7



Lines i get downloading more files:

Code: Select all
max2
Value:1.jpg
Value:aboutaction.html
Root:null
/web/../../1.jpg
Directory:/web/../..
In:null
Error: java.lang.NullPointerException




So you see the Root is different but i don't know how it comes.

Here is the code when i pres for downlaoding:
Code: Select all
else if (evt.getSource() == bDownload)
        {
           try{
               int maxRows;
               int[] selRows;
               
                    selRows = table1.getSelectedRows();
                    maxRows = table1.getSelectedRowCount();
                    System.out.println("max"+maxRows);
                    if (selRows.length > 0) {
                       for (int a = 0; a < maxRows; a++){
                          for (int i= 0; i < 3 ; i++) {
                             TableModel tm = table1.getModel();
                             size2 = tm.getValueAt(selRows[a],2);
                             if (i==1){
                                 value = tm.getValueAt(selRows[a],i);
                                System.out.println("Value:" + value);
                                threadDownload((String) value);
                             }
                          }
                          }
                       }
               } catch (Exception e){System.out.println(e.toString());}
        }




Then here is the thread:

Code: Select all
public synchronized void threadDownload(final String valueString) {       
       new Thread(new Runnable() {
            public void run() {
               try{
               wrapper.changeWorkingDirectory(Root);
               System.out.println("Root:" +wrapper.printWorkingDirectory());
               Object size = size2;
                doDownload(valueString,size);
               }
               catch (Exception e){}
            }
        }).start();
    }




Here is the code for uploading the file:

Code: Select all
public synchronized void doDownload(String myValue,Object size2) {
      try {
          //wrapper.changeWorkingDirectory(Root);
         lUpload.setText("Downloading file : " + myValue);
            lUpload.setVisible(true);
          aProgressBar.setVisible(true);
          aProgressBar.setStringPainted(true);
          bDownload.setEnabled(false);
            bUpload.setEnabled(false);
            bMkdirC.setEnabled(false);
            bMkdirS.setEnabled(false);
            table.setEnabled(false);
            table1.setEnabled(false);
            bFindLoc.setEnabled(false);
            bFindSer.setEnabled(false);
          remoteFileName = Root + "/" + myValue;
          //remoteFileName = myValue;
          localFileName = path + "/" + myValue;
          byte[] buffer = new byte[1024];

          String size8 = size2.toString();
            int size = Integer.parseInt(size8);
           
          aProgressBar.setMaximum(100);
          
          FileOutputStream out = new FileOutputStream(localFileName);
          System.out.println(remoteFileName);
          System.out.println("Directory:" +wrapper.printWorkingDirectory());
          InputStream in = wrapper.retrieveFileStream(remoteFileName);
          System.out.println("In:"+in);
          int counter = 0;
            double bytesDown = 0;
            int percVal = 0;
           
            while ((counter = in.read(buffer)) >= 0 ) {
               
                bytesDown += counter;
                out.write(buffer,0,counter);
                percVal = (int) ((bytesDown / size) * 100);
                aProgressBar.setValue(percVal);
                aProgressBar.setString("" + percVal + "%");
                if (percVal == 100){
                   refreshDownload();
                   refreshUpload();
                }
            }
            out.close();
             in.close();
       } catch (Exception ex) {
          System.out.println("Error: " + ex.toString()+ " message: " + ex.getMessage());
       }
    }




Hope you can help me

Satanduvel
Satanduvel
 
Posts: 8
Joined: Thu Apr 19, 2007 11:20 am

Postby Satanduvel on Tue Apr 24, 2007 9:50 am

Pls can somebody help me?

Satanduvel
Satanduvel
 
Posts: 8
Joined: Thu Apr 19, 2007 11:20 am

Postby ggomez on Tue Apr 24, 2007 5:32 pm

InputStream in = wrapper.retrieveFileStream(remoteFileName);

your not getting the inputstream so it stay in "null"
check if the archives exist or if the method that returns the inputstream works fine.

good luck
ggomez
 
Posts: 45
Joined: Tue Apr 17, 2007 3:30 am
Location: !!!!!MéXiCo¡¡¡¡¡¡

Postby Satanduvel on Wed Apr 25, 2007 6:37 am

I found the problem but thx for replying

Satanduvel
Satanduvel
 
Posts: 8
Joined: Thu Apr 19, 2007 11:20 am


Who is online

Users browsing this forum: No registered users and 1 guest