If i select 1 file i can upload it but when i'm selecting 2 or more i get the error org.apache.commons.net.MalformedServerReplyExcepti on: Truncated server reply .
Here is my code
So when i click the button threadUpload will be called:
Expand|Select|Wrap|Line Numbers
- else if (evt.getSource() == bUpload)
- {
- try{
- int maxRows;
- int[] selRows;
- selRows = table.getSelectedRows();
- maxRows = table.getSelectedRowCount();
- System.out.println("max"+maxRows);
- if (selRows.length > 0) {
- for (int a = 0; a < maxRows; a++){
- for (int i= 0; i < 3 ; i++) {
- if (i==1){
- TableModel tm = table.getModel();
- value = tm.getValueAt(selRows[a],i);
- System.out.println("value:" + value);
- threadUpload();
- //wait(50000000);
- }
- }
- }
- }
- } catch (Exception e){}
- }
Then this is the tread thats starts the uploading
Expand|Select|Wrap|Line Numbers
- public void threadUpload() {
- t = new Thread(new Runnable() {
- public void run() {
- //Get the path + name of the selected File
- String allText = path+value;
- System.out.println("filename:" + allText);
- doUpload(allText);
- }
- });
- try{
- t.start();
- } catch (Exception e){}
- }
Then is this the code for uploaden the file:
Expand|Select|Wrap|Line Numbers
- public void doUpload(String filename) {
- if (wrapper.isConnected()){
- try{
- wrapper.changeWorkingDirectory(Root);
- wrapper.binary();
- lUpload.setText("Uploading file : " + value);
- lUpload.setVisible(true);
- aProgressBar.setVisible(true);
- aProgressBar.setStringPainted(true);
- byte[] buffer = new byte[1024];
- try {
- String remoteFile = (String) value;
- System.out.println("remotefile:"+remoteFile);
- File f = new File(filename);
- int size = (int) f.length();
- FileInputStream in = new FileInputStream(filename);
- OutputStream out = wrapper.storeFileStream(remoteFile);
- int counter = 0;
- double bytesUploaded = 0;
- int percVal = 0;
- System.out.println("Root: " + Root);
- while ((counter = in.read(buffer)) >= 0 ) {
- bytesUploaded += counter;
- out.write(buffer,0,counter);
- percVal = (int) ((bytesUploaded / size) * 100);
- aProgressBar.setValue(percVal);
- aProgressBar.setString("" + percVal + "%");
- if (percVal == 100){
- refreshUpload();
- JOptionPane.showMessageDialog(this,"Uploaden geslaagd","Gelukt",JOptionPane.INFORMATION_MESSAGE);
- lUpload.setVisible(false);
- aProgressBar.setVisible(false);
- }
- }
- out.close();
- in.close();
- } catch (Exception ex) {
- System.out.println(ex);
- JOptionPane.showMessageDialog(this,"Error: " + ex.toString(),"ERROR",JOptionPane.ERROR_MESSAGE);
- aProgressBar.setVisible(false);
- }
- } catch (Exception ex) {
- System.out.println(ex);
- JOptionPane.showMessageDialog(this,"Connectie Error: " + ex.toString(),"ERROR",JOptionPane.ERROR_MESSAGE);
- }
- } else {
- System.out.println("Geen connectie tijdens het uploaden...");
- JOptionPane.showMessageDialog(this,"Geen connectie tijdens het uploaden","ERROR",JOptionPane.ERROR_MESSAGE);
- connect();
- return;
- }
- postUpload();
- }
So my opinion is that the treads are being covered(overwriting) by the other when i upload more than 1 file.
I hope somebody can help me.
Satanduvel