473,396 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Upload multiple files to ftp

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.MalformedServerReplyExcepti on: Truncated server reply .

Here is my code

So when i click the button threadUpload will be called:

Expand|Select|Wrap|Line Numbers
  1. else if (evt.getSource() == bUpload)
  2.         {
  3.             try{
  4.             int maxRows;
  5.             int[] selRows;
  6.  
  7.                  selRows = table.getSelectedRows();
  8.                  maxRows = table.getSelectedRowCount();
  9.                  System.out.println("max"+maxRows);
  10.                  if (selRows.length > 0) {
  11.                     for (int a = 0; a < maxRows; a++){
  12.                     for (int i= 0; i < 3 ; i++) {
  13.                         if (i==1){
  14.                             TableModel tm = table.getModel();
  15.                             value = tm.getValueAt(selRows[a],i);
  16.                             System.out.println("value:" + value);
  17.                                     threadUpload();
  18.                             //wait(50000000);
  19.                              }
  20.                          }
  21.                      }
  22.                 }
  23.             } catch (Exception e){}
  24.         }


Then this is the tread thats starts the uploading


Expand|Select|Wrap|Line Numbers
  1. public void threadUpload() {
  2.  
  3.         t = new Thread(new Runnable() {
  4.             public void run() {
  5.                 //Get the path + name of the selected File
  6.                 String allText = path+value;
  7.                 System.out.println("filename:" + allText);
  8.                 doUpload(allText);
  9.             }
  10.         });
  11.         try{
  12.         t.start();
  13.         } catch (Exception e){}
  14.     }


Then is this the code for uploaden the file:


Expand|Select|Wrap|Line Numbers
  1. public void doUpload(String filename) {
  2.         if (wrapper.isConnected()){
  3.             try{
  4.                 wrapper.changeWorkingDirectory(Root);
  5.                 wrapper.binary();
  6.                 lUpload.setText("Uploading file : " + value);
  7.                 lUpload.setVisible(true);
  8.                 aProgressBar.setVisible(true);
  9.                 aProgressBar.setStringPainted(true);
  10.                 byte[] buffer = new byte[1024];
  11.                 try {
  12.                     String remoteFile = (String) value;
  13.                     System.out.println("remotefile:"+remoteFile);
  14.                     File f = new File(filename);
  15.                     int size = (int) f.length();
  16.                     FileInputStream in = new FileInputStream(filename);
  17.                     OutputStream out = wrapper.storeFileStream(remoteFile);
  18.                     int counter = 0;
  19.                     double bytesUploaded = 0;
  20.                     int percVal = 0;
  21.                     System.out.println("Root: " + Root);
  22.                     while ((counter = in.read(buffer)) >= 0 ) {
  23.                         bytesUploaded += counter;
  24.                         out.write(buffer,0,counter);
  25.                         percVal = (int) ((bytesUploaded / size) * 100); 
  26.                         aProgressBar.setValue(percVal);
  27.                         aProgressBar.setString("" + percVal + "%");
  28.                         if (percVal == 100){
  29.                         refreshUpload();
  30.                         JOptionPane.showMessageDialog(this,"Uploaden geslaagd","Gelukt",JOptionPane.INFORMATION_MESSAGE);
  31.                         lUpload.setVisible(false);
  32.                         aProgressBar.setVisible(false);
  33.                         }
  34.                     }
  35.                     out.close();
  36.                     in.close();
  37.                 } catch (Exception ex) {
  38.                     System.out.println(ex);
  39.                     JOptionPane.showMessageDialog(this,"Error: " + ex.toString(),"ERROR",JOptionPane.ERROR_MESSAGE);
  40.                     aProgressBar.setVisible(false);
  41.                 }
  42.             } catch (Exception ex) {
  43.                 System.out.println(ex);
  44.                 JOptionPane.showMessageDialog(this,"Connectie Error: " + ex.toString(),"ERROR",JOptionPane.ERROR_MESSAGE);
  45.             }
  46.         } else {
  47.             System.out.println("Geen connectie tijdens het uploaden...");
  48.             JOptionPane.showMessageDialog(this,"Geen connectie tijdens het uploaden","ERROR",JOptionPane.ERROR_MESSAGE);
  49.             connect();
  50.             return;
  51.         }
  52.         postUpload();
  53.     }


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
Apr 18 '07 #1
1 3425
Pls somebody has an answer?

Satanduvel
Apr 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: x. zhang | last post by:
Hi Guys, We know that we can use <input type=file ...> to upload one file per time to the server. My question is if there are some way to upload multiple files per time to the server. (Of...
5
by: Jason | last post by:
I have a potential need to upload multiple PDF legal documents. Is it possible to attach more than one file per upload?
7
by: crowl | last post by:
Hi there, I am looking for a component allowing me uploading multiple files by my asp page. I have found several components achieving this by require a <input type="file" name="FileX"> field for...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
7
by: der_grobi | last post by:
That is the Problem: I have an ASP.NET Webapplicatipon where I can upload single files to the Server. That works fine. But now, I want to Upload multiple files. I know the path of the files, i...
6
by: Milan Krejci | last post by:
while(list($key,$value) = each($_FILES)) { if(!empty($value)){ $filename = $value; $add = "upimg/$filename"; echo $_FILES; $error=copy($_FILES, $add); if (!$error)...
43
by: bonneylake | last post by:
Hey Everyone, Well this is my first time asking a question on here so please forgive me if i post my question in the wrong section. What i am trying to do is upload multiple files like gmail...
4
by: MoroccoIT | last post by:
Greetings - I saw somewhat similar code (pls see link below) that does mupltiple files upload. It works fine, but I wanted to populate the database with the same files that are uploaded to...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.