Java tutorial
package vv; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.commons.net.ftp.FTPClient; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author GP12 */ public class main extends javax.swing.JFrame { /** * Creates new form main */ public main() { 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">//GEN-BEGIN:initComponents private void initComponents() { btnBackup = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); txtLog = new javax.swing.JTextArea(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); btnBackup.setText("Backup"); btnBackup.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnBackupActionPerformed(evt); } }); txtLog.setColumns(20); txtLog.setRows(5); txtLog.setEnabled(false); jScrollPane1.setViewportView(txtLog); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(23, 23, 23).addComponent(btnBackup) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE) .addComponent(btnBackup).addGap(129, 129, 129))); pack(); }// </editor-fold>//GEN-END:initComponents private void btnBackupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackupActionPerformed // TODO add your handling code here: Conectar con = new Conectar(); String nombreCarpeta = "FTF_" + con.getTime("dd-MM-yyyy") + "_" + con.getTime("HHmm"); con.createDir("c:\\tmp\\" + nombreCarpeta); FTPClient client = new FTPClient(); String sFTP = con.IP_FTP; String sUser = con.USUARIO_FTP; String sPassword = con.PASSWORD_FTP; txtLog.setText("INICIO: " + con.getTime("dd-MM-yyyy HH:mm:ss")); try { client.connect(sFTP); boolean login = client.login(sUser, sPassword); con.copiarDir(client, nombreCarpeta); client.logout(); client.disconnect(); } catch (Exception e) { System.out.println("Error:" + e); } txtLog.setText(txtLog.getText() + "\nFIN: " + con.getTime("dd-MM-yyyy HH:mm:ss")); }//GEN-LAST:event_btnBackupActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new main().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnBackup; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea txtLog; // End of variables declaration//GEN-END:variables }