Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java program with Commons-net Library

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java program with Commons-net Library

    I have a java program with common-net library. It works fine in windows when i run it from eclipse. But when i try to run the file from Unix it doesn't seem to like the FTPClient class that i imported from java common-net library. My library's are in jar file that i added to my sourceBuild path when i included in the project. Here is my code:

    import java.awt.event.*;
    import java.awt.*;
    import java.io.*;
    import java.text.ParseException;
    import javax.swing.*;
    import javax.swing.UIManager.LookAndFeelInfo;
    import javax.swing.text.MaskFormatter;

    import org.apache.commons.net.ftp.FTPClient;

    public class ReTransmitToVendor {

    public static void main (String []args)

    {

    Runnable runner = new Runnable()
    {
    public void run()
    {


    try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
    if ("Nimbus".equals(info.getName())) {
    UIManager.setLookAndFeel(info.getClassName());
    break;
    }
    }
    } catch (Exception e) {

    }


    JFrame frame = new JFrame("Ftp Re-Transmit");
    frame.setSize(800, 420);
    frame.setVisible(true);
    frame.setLocation(200, 200);
    frame.setResizable(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    JMenu programMenu = new JMenu("Program");
    menuBar.add(programMenu);
    final JMenuItem exitItem = new JMenuItem("Exit", new ImageIcon ("exit.png"));
    programMenu.add(exitItem);


    JMenu helpMenu = new JMenu("Help");
    menuBar.add(new JPanel());
    menuBar.add(helpMenu);
    final JMenuItem aboutItem = new JMenuItem("About", new ImageIcon("about.png"));
    helpMenu.add(aboutItem);


    JPanel topPanel = new JPanel(new BorderLayout());
    frame.add(topPanel, BorderLayout.NORTH);

    JPanel titlePanel = new JPanel(new FlowLayout());
    topPanel.add(titlePanel);
    JLabel titleLabel = new JLabel("Ftp-Retransmit To Vendor");
    titleLabel.setFont(new Font (null, Font.BOLD, 14));
    titleLabel.setForeground(Color.BLUE);
    titlePanel.add(titleLabel);

    JPanel gridPanel = new JPanel(new GridLayout(2, 2));
    frame.add(gridPanel);

    JPanel comboBoxPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    gridPanel.add(comboBoxPanel);
    String [] vendors = {"68.98.136.5:21"};
    JComboBox vendorComboBox = new JComboBox(vendors);
    comboBoxPanel.add(vendorComboBox);

    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    gridPanel.add(buttonPanel);
    final JButton transmitButton = new JButton("Re-Transmit");
    buttonPanel.add(transmitButton);

    JPanel filePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    gridPanel.add(filePanel);
    JLabel fileLabel = new JLabel("File: ");
    fileLabel.setFont(new Font(null, Font.BOLD, 12));
    filePanel.add(fileLabel);
    final JTextField fileNameField = new JTextField(30);
    fileNameField.setEditable(false);
    filePanel.add(fileNameField);


    JPanel browsePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    gridPanel.add(browsePanel);
    final JButton browseButton = new JButton("Browse");
    browseButton.setMargin(new Insets(0,12,0,12));
    browsePanel.add(browseButton);


    ActionListener menuItemListener = new ActionListener()
    {
    public void actionPerformed(ActionEvent ae)
    {
    if (ae.getSource()== exitItem)
    {

    JOptionPane.showMessageDialog(null, "You're Program is about exit!");
    System.exit(0);
    }
    else if (ae.getSource() == aboutItem)
    {
    JOptionPane.showMessageDialog(null, "This software was created to Re-transmit to vendor");
    }
    }
    };
    exitItem.addActionListener(menuItemListener);
    aboutItem.addActionListener(menuItemListener);

    ActionListener browseListener = new ActionListener()
    {
    public void actionPerformed(ActionEvent e)

    {
    if (e.getSource() == browseButton)
    {


    final JFileChooser fileChooser = new JFileChooser();

    int showFileChooser = fileChooser.showOpenDialog(null);

    File getFile = fileChooser.getSelectedFile();

    if (showFileChooser == fileChooser.APPROVE_OPTION)
    {

    fileNameField.setText(getFile.getAbsolutePath());

    }


    }


    }
    };
    browseButton.addActionListener(browseListener);

    ActionListener transmitButtonListener = new ActionListener ()
    {
    public void actionPerformed(ActionEvent tbl)
    {
    if (tbl.getSource()== transmitButton)
    {

    String getDirectory = fileNameField.getText();

    FTPClient client = new FTPClient();
    try
    {
    client.connect("pearl.bna.com");
    client.login("####", "######");
    System.out.println(client.getReplyString());
    File saveFile = new File (getDirectory);
    FileInputStream fis = new FileInputStream(saveFile);
    client.storeFile(saveFile.getName().toString(), fis);


    }
    catch (Exception e)
    {
    e.printStackTrace();
    }




    }
    }

    };
    transmitButton.addActionListener(transmitButtonLis tener);



    }

    };
    EventQueue.invokeLater(runner);

    }

    }


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Java program with Commons-net Library

    Please see the Announcements page for the use of code tags and other useful forum tips.
    it doesn't seem to like
    Please do not translate error messages, copy paste them to the forum with your code and question.

Similar Threads

  1. Commons net 2.2 api
    By karating in forum Java Networking
    Replies: 1
    Last Post: May 22nd, 2013, 07:07 PM
  2. need help with 'org.apache.commons.net.ftp.FTPClient'
    By rtumatt in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 22nd, 2013, 07:02 PM
  3. Replies: 0
    Last Post: April 5th, 2013, 10:20 AM
  4. Uploading File to server ( Apache.commons.net)
    By quirell in forum Java Networking
    Replies: 5
    Last Post: November 11th, 2012, 11:06 PM
  5. Scanning large FTP directories with apache.commons.net.ftp
    By daniel_el in forum Java Theory & Questions
    Replies: 3
    Last Post: February 10th, 2012, 06:40 AM

Tags for this Thread