ragazzi ho fatto il seguente codice senza nessun errore:
però quando seleziono un file e clicco sul bottone upload e controllo nel sito di altervista non trovo niente.... cosa sbaglio?codice:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * NumberAdditionUI.java * * Created on 29-gen-2009, 16.39.39 */ package my.numeraddition; import javax.swing.*; import sun.net.ftp.*; import sun.net.TelnetOutputStream; import java.io.File; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.FileInputStream; /** * * @author corradocacciapuoti */ public class NumberAdditionUI extends javax.swing.JFrame { /** Creates new form NumberAdditionUI */ public NumberAdditionUI() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jTabbedPane1 = new javax.swing.JTabbedPane(); jButton3 = new javax.swing.JButton(); jTextField1 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButton3.setText("Scegli il file..."); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jTextField1.setEditable(false); jButton1.setText("Upload"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .addContainerGap(35, Short.MAX_VALUE) .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 136, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(18, 18, 18) .add(jButton3) .add(49, 49, 49)) .add(layout.createSequentialGroup() .add(144, 144, 144) .add(jButton1) .addContainerGap(135, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(39, 39, 39) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jButton3) .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(57, 57, 57) .add(jButton1) .addContainerGap(107, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser (); chooser.showOpenDialog(null); String file=(chooser.getSelectedFile().getAbsolutePath()); jTextField1.setText ("" + file); } Qua inizia il codice alla pressione del bottone upload private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String server="scaricomacfile.altervista.org"; String userName="scaricomacfile"; String pw="xxxxxxxx"; String fileName=jTextField1.getText(); FtpClient ftpClient = new FtpClient(); try { ftpClient.openServer(server); ftpClient.login(userName, pw); ftpClient.cd("/"); ftpClient.binary(); TelnetOutputStream netOut = ftpClient.put(fileName); File file = new File(fileName); ObjectInputStream fileIn = new ObjectInputStream(new FileInputStream(file)); byte c[]= new byte[1000]; int read = 0; while ((read = fileIn.read(c)) != -1) { netOut.write(c, 0, read); } fileIn.close(); netOut.close(); ftpClient.closeServer(); } catch (Exception ex) { } } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new NumberAdditionUI().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton3; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JTextField jTextField1; // End of variables declaration }

Rispondi quotando
grazie mille
