The Artima Developer Community
Sponsored Link

Java Answers Forum
Applet upload multiple files to ftp

1 reply on 1 page. Most recent reply: Apr 20, 2007 4:50 AM by Thomas Sels

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Thomas Sels

Posts: 4
Nickname: satanduvel
Registered: Apr, 2007

Applet upload multiple files to ftp Posted: Apr 18, 2007 6:24 AM
Reply to this message Reply
Advertisement
Hello i'm making an applet that has 2 JTables en when you select a file in a JTable you can upload the file. 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.MalformedServerReplyException: Truncated server reply .

Here is my code

So when i click the button threadUpload will be called:

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

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:

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 by the other when i upload more than 1 file.

I hope somebody can help me.

Satanduvel


Thomas Sels

Posts: 4
Nickname: satanduvel
Registered: Apr, 2007

Re: Applet upload multiple files to ftp Posted: Apr 20, 2007 4:50 AM
Reply to this message Reply
Nobody that can help me?
If you can pls help me i have to do this project 4 school and the deadline is comming closer.

Satanduvel

Flat View: This topic has 1 reply on 1 page
Topic: Applet upload multiple files to ftp Previous Topic   Next Topic Topic: problem with  re-throwing exception

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use