0

I know that there are multiple formats for ftp uploads.(Binary ascii etc…) I am writing a simple app to transfer files between my computer and a raspberry pi and I would like to know if there is a simple way to ensure that the upload is of the proper type. Additionally, I have been trying hard to get an upload of a .jar file to succeed with no luck. I believe that this is the same problem as already mentioned. Here is the code

private void uploadActionPerformed(java.awt.event.ActionEvent evt) {                                       
        FileInputStream in = null;
         int returnVal = filechooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = filechooser.getSelectedFile();
        try{
            FTPClient f = new FTPClient();

            f.connect("********");
            f.login("*******", "********");
            in = new FileInputStream(file.getAbsolutePath());
            f.storeFile("public_html/GEdropbox/" + file.getName(),in);
            in.close();
            f.disconnect();
        }catch(IOException e){
            System.out.println("not working");
        }
    } else {
        System.out.println("File access cancelled by user.");
    }
}                                 

1 Answers1

0

Set binary transfer mode:

f.connect("********");
f.login("*******", "********");
f.setFileType(FTP.BINARY_FILE_TYPE);
MGorgon
  • 2,547
  • 23
  • 41
  • That fixes the jar problem but how to I make the code discriminate between types? – a_river_in_canada Jun 18 '14 at 20:59
  • You don't have to, unless both systems are using this same encoding. If you're using binary transfer, file is passed as-is. When transfering in ASCII, client/server have to convert ASCII table to it's own code page. Read more here: http://www.serv-u.com/newsletter/NewsL2008-03-18.asp – MGorgon Jun 18 '14 at 21:07
  • Thanks I did need to tell both systems to use the same encoding, but my problem is fixed. Also thanks for the link to the article. I read through it. – a_river_in_canada Jun 18 '14 at 21:30