T
TimC
Gast
Hallo,
also ich habe folgendes Problem:
Ich habe keine Ahnung von JAVA brauche auch dringend ein kleines FTP Upload-Tool. Habe mir dafür ein JAVA-Applet aus dem Internet geladen. Dieses Applet ist OpenSource und ist "eigentlich" genau was ich suche. Nur hätte ich da ein paar kleine änderungen.
Wenn ich die applet.jar öffne mit die darin liegende "ZUpload.java" mal so anschaue:
habe ich ja eigentlich alles was ich brauche um dieses, vom Layout her, abzuändern bzw. anzupassen. Nur leider bekommte ich noch nicht einmal diese *.java Datei zurück in einen *.jar Datei.
Währ vielleicht einer bereit mir diese Script einbisschen abzuändern?
Gruß u. Danke
TimC
also ich habe folgendes Problem:
Ich habe keine Ahnung von JAVA brauche auch dringend ein kleines FTP Upload-Tool. Habe mir dafür ein JAVA-Applet aus dem Internet geladen. Dieses Applet ist OpenSource und ist "eigentlich" genau was ich suche. Nur hätte ich da ein paar kleine änderungen.
Wenn ich die applet.jar öffne mit die darin liegende "ZUpload.java" mal so anschaue:
Code:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.EventObject;
import javax.swing.*;
import net.sf.jftp.net.*;
public class ZUpload extends JApplet
implements ConnectionListener, ActionListener
{
public ZUpload()
{
}
public void init()
{
bParamsSet = false;
fcChooser = new JFileChooser();
fcChooser.setMultiSelectionEnabled(true);
bAddFile = new JButton("Add File");
bAddFile.addActionListener(this);
bRemoveFile = new JButton("Remove File");
bRemoveFile.addActionListener(this);
bUpload = new JButton("Upload Files");
bUpload.addActionListener(this);
pbFile = new JProgressBar();
pbTotal = new JProgressBar();
pbFile.setMinimum(0);
pbFile.setMaximum(10000);
pbTotal.setMinimum(0);
pbTotal.setMaximum(10000);
bFileComplete = true;
lFiles = new JList();
spList = new JScrollPane(lFiles);
alFiles = new ArrayList();
lTotalCompleteSize = lTotalSize = lFileSize = lFileCompleteSize = 0L;
contentPane = getContentPane();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
contentPane.setLayout(gridbag);
c.fill = 2;
c.weightx = 0.5D;
c.gridx = 2;
c.gridy = 1;
c.insets = new Insets(40, 0, 0, 0);
gridbag.setConstraints(bAddFile, c);
contentPane.add(bAddFile);
c.weightx = 0.5D;
c.gridx = 2;
c.gridy = 2;
c.insets = new Insets(0, 0, 0, 0);
gridbag.setConstraints(bRemoveFile, c);
contentPane.add(bRemoveFile);
c.weightx = 0.5D;
c.gridx = 2;
c.gridy = 3;
c.insets = new Insets(0, 0, 0, 0);
gridbag.setConstraints(bUpload, c);
contentPane.add(bUpload);
c.weightx = 3D;
c.weighty = 5D;
c.anchor = 11;
c.fill = 1;
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 1;
c.gridheight = 4;
c.insets = new Insets(0, 0, 0, 0);
gridbag.setConstraints(spList, c);
contentPane.add(spList);
c.fill = 2;
c.anchor = 15;
c.weightx = 1.0D;
c.weighty = 0.20000000000000001D;
c.gridx = 0;
c.gridy = 5;
c.insets = new Insets(10, 0, 10, 0);
c.gridheight = 1;
c.gridwidth = 3;
gridbag.setConstraints(pbFile, c);
contentPane.add(pbFile);
c.gridx = 0;
c.gridy = 6;
c.insets = new Insets(10, 0, 10, 0);
c.gridheight = 1;
c.gridwidth = 3;
gridbag.setConstraints(pbTotal, c);
contentPane.add(pbTotal);
param_host = getParameter("host");
param_user = getParameter("user");
param_pass = getParameter("pass");
param_path = getParameter("path");
param_postscript = getParameter("postscript");
}
public void start()
{
if(param_host == null || param_user == null || param_pass == null || param_path == null)
bParamsSet = false;
else
bParamsSet = true;
}
public void updateRemoteDirectory(BasicConnection basicconnection)
{
}
public void connectionInitialized(BasicConnection con)
{
connected = true;
}
public void updateProgress(String file, String type, long bytes)
{
if(bytes > 0L)
lFileCompleteSize = bytes;
updateProgressBar();
}
public void connectionFailed(BasicConnection con, String why)
{
System.out.println("connection failed!");
}
public void actionFinished(BasicConnection con)
{
lFileCompleteSize = lFileSize;
lTotalCompleteSize += lFileSize;
updateProgressBar();
removeFile(0);
updateList();
repaint();
if(!alFiles.isEmpty())
{
lFiles.setSelectedIndex(0);
pbFile.setValue(0);
File current = (File)alFiles.get(0);
lFileSize = current.length();
lFileCompleteSize = 0L;
con.handleUpload(current.getAbsolutePath());
} else
if(param_postscript != null)
try
{
URL url = new URL(param_postscript);
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
protected void updateProgressBar()
{
int percent = (int)(((float)lFileCompleteSize / (float)lFileSize) * 10000F);
pbFile.setValue(percent);
pbFile.setString(lFileCompleteSize / 1024L + "/" + lFileSize / 1024L + " kB");
percent = (int)(((float)lTotalCompleteSize / (float)lTotalSize) * 10000F);
pbTotal.setString(lTotalCompleteSize / 1024L + "/" + lTotalSize / 1024L + " kB");
pbTotal.setValue(percent);
repaint();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == bAddFile)
{
int returnVal = fcChooser.showOpenDialog(null);
if(returnVal == 0)
{
File files[] = fcChooser.getSelectedFiles();
addFiles(files);
updateList();
updateSize();
repaint();
fcChooser.setSelectedFile(null);
}
} else
if(e.getSource() == bRemoveFile)
{
int removeidx = lFiles.getSelectedIndex();
if(removeidx >= 0)
removeFile(removeidx);
updateList();
updateSize();
repaint();
} else
if(e.getSource() == bUpload)
uploadFiles();
}
protected void uploadFiles()
{
if(alFiles.isEmpty())
return;
if(!bParamsSet)
return;
pbFile.setStringPainted(true);
pbTotal.setStringPainted(true);
pbFile.setString("0/0 kB");
pbTotal.setString("0/0 kB");
con = new FtpConnection(param_host);
con.addConnectionListener(this);
ConnectionHandler handler = new ConnectionHandler();
con.login(param_user, param_pass);
while(!connected)
try
{
Thread.sleep(10L);
}
catch(Exception ex)
{
ex.printStackTrace();
}
con.chdir(param_path);
if(alFiles.isEmpty())
{
return;
} else
{
lFiles.setSelectedIndex(0);
File current = (File)alFiles.get(0);
lFileSize = current.length();
lFileCompleteSize = 0L;
bFileComplete = false;
con.handleUpload(current.getAbsolutePath());
return;
}
}
protected void addFiles(File files[])
{
boolean skip = false;
for(int i = 0; i < files.length; i++)
{
skip = false;
if(alFiles.size() == 0)
{
alFiles.add(files[i]);
} else
{
for(int j = 0; j < alFiles.size(); j++)
{
if(!((File)alFiles.get(j)).equals(files[i]))
continue;
skip = true;
break;
}
if(!skip)
alFiles.add(files[i]);
}
}
}
protected void removeFile(int index)
{
if(index < alFiles.size())
alFiles.remove(index);
}
protected void updateList()
{
int size = alFiles.size();
String sFileList[] = new String[size];
for(int i = 0; i < size; i++)
{
File temp = (File)alFiles.get(i);
sFileList[i] = temp.getName();
}
lFiles.setListData(sFileList);
}
protected void updateSize()
{
lTotalSize = 0L;
for(int i = 0; i < alFiles.size(); i++)
{
File temp = (File)alFiles.get(i);
lTotalSize += temp.length();
}
}
protected FtpConnection con;
protected boolean connected;
protected boolean bFileComplete;
protected boolean bParamsSet;
protected JFileChooser fcChooser;
protected ArrayList alFiles;
protected JButton bAddFile;
protected JButton bRemoveFile;
protected JButton bUpload;
protected JList lFiles;
protected Container contentPane;
protected JProgressBar pbFile;
protected JProgressBar pbTotal;
protected JScrollPane spList;
protected long lTotalSize;
protected long lTotalCompleteSize;
protected long lFileSize;
protected long lFileCompleteSize;
protected String param_host;
protected String param_user;
protected String param_pass;
protected String param_path;
protected String param_postscript;
}
Währ vielleicht einer bereit mir diese Script einbisschen abzuändern?
Gruß u. Danke
TimC