Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By Norm

Thread: Writing to File on FTP

  1. #1
    jtd200 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Writing to File on FTP

    I've been beating my head against this wall for 8-10 hours, today. Please help if you can!

    I have a java applet which uses an Apache FTPClient to download some information from a file, then use that information to write a file onto that same FTP server. These are all located in the same directory as the applet itself. When I run this applet in my Eclipse Applet Viewer, it works perfectly, writing the information to the FTP. When I load it from the browser, however, it hangs at that point and never writes. I've signed the only .jar file, and nothing seems to be working. Is there anything else I might be missing?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Writing to File on FTP

    WHat does your code around the write look like?

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Writing to File on FTP

    it hangs at that point
    Add some printlns to show exactly where the code is blocking.
    Do you have a log for the server that will show you where the communications between the applet and the server is stopping?

    Are there any error messages in the browser's java console?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Writing to File on FTP

    Cross posted at Applet Not Writing to FTP
    DarrylBurke likes this.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Writing to File on FTP

    Thanks for the heads-up.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    jtd200 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Writing to File on FTP

    Thanks for the quick responses! Here is the writing portion of the code:
    ////////////////////////////////////
    Java Code:
    FTPClient client = new FTPClient();
    			
    			try {
    				client.connect("ftp.ugly-dogs.com");
    				client.login("username", "password");
    				 
    				//write to HiScore.hi
    				OutputStream out1 = client.storeFileStream("/640480/HiScore.hi");
    				BufferedWriter bufferedWriter1 = new BufferedWriter(new OutputStreamWriter(out1));
    				
    				for(int i = 0; i < scores.size(); i++){
    					bufferedWriter1.write(<a string>);
    					
    					bufferedWriter1.newLine();
    				}
    				bufferedWriter1.close();
    				//out1.close();
    				
    				client.connect("ftp.ugly-dogs.com");
    				client.login("username", "password");
    				//write to HiScore.html
    				BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(client.storeFileStream("/640480/HiScore.html")));
    				
    				bufferedWriter.write("<html>");bufferedWriter.newLine();
    				bufferedWriter.write("<table border=\"1\">");bufferedWriter.newLine();
    				bufferedWriter.write("<tr>");bufferedWriter.newLine();
    				bufferedWriter.write("<th>Rank</th>");bufferedWriter.newLine();
    				bufferedWriter.write("<th>Name</th>");bufferedWriter.newLine();
    				bufferedWriter.write("<th>Race</th>");bufferedWriter.newLine();
    				bufferedWriter.write("<th>Level</th>");bufferedWriter.newLine();
    				bufferedWriter.write("<th>Gold</th>");bufferedWriter.newLine();
    				bufferedWriter.write("<th>Kills</th>");bufferedWriter.newLine();
    				bufferedWriter.write("<th>Map Level</th>");bufferedWriter.newLine();
    				bufferedWriter.write("</tr>");bufferedWriter.newLine();
    				
    				for(int i = 0; i < scores.size(); i++){
    					bufferedWriter.write("<tr>");bufferedWriter.newLine();
    					bufferedWriter.write("<td>" + (i+1) + "</td>");bufferedWriter.newLine();
    					bufferedWriter.write("<td>" + scores.get(i).name + "</td>");bufferedWriter.newLine();
    					bufferedWriter.write("<td>" + scores.get(i).race + "</td>");bufferedWriter.newLine();
    					bufferedWriter.write("<td>" + scores.get(i).level + "</td>");bufferedWriter.newLine();
    					bufferedWriter.write("<td>" + scores.get(i).gold + "</td>");bufferedWriter.newLine();
    					bufferedWriter.write("<td>" + scores.get(i).kills + "</td>");bufferedWriter.newLine();
    					bufferedWriter.write("<td>" + scores.get(i).mapLevel + "</td>");bufferedWriter.newLine();
    					bufferedWriter.write("</tr>");bufferedWriter.newLine();
    					
    				}
    				
    				bufferedWriter.write("</table>");bufferedWriter.newLine();
    				bufferedWriter.write("</html>");
    				
    				bufferedWriter.close();
    				//client.storeFileStream("/640480/HiScore.html").close();
    				//client.disconnect();
    			
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
    ////////////////////////////////////

    I've tried a few different things with it... I just figure it's something to do with securities since I can run it perfectly from Applet Viewer...
    Last edited by Norm; 01-13-2012 at 06:46 PM.

  7. #7
    jtd200 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Writing to File on FTP

    Also, the process I followed to sign the jar was just: "keytool -genkeypair" .... followed by "jarsigner file.jar keyname", after which it told me the certificate would expire within 6 months. Is that the correct process, or am I missing something else there?

    By the way, is that other site (where I "cross-posted") related to this one, and is doing that frowned upon? If so, sorry!
    Last edited by jtd200; 01-13-2012 at 06:25 PM.

  8. #8
    jtd200 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Writing to File on FTP

    Ok - (sorry for all of the posts) I'm getting this:

    AWT-EventQueue-2" java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClient


    I do not get this error when I compile. I followed the directions that I'd found to install Apache's net library... Do I have to add the apache class files to the .jar or something?

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Writing to File on FTP

    You need to make the jar file with the missing class available to the browser. Use the <APPLET tag's archive= attribute to do that.

  10. #10
    jtd200 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Writing to File on FTP

    IT WORKS! Sorry for wasting everyone's time - as soon as I checked the log, I realized it wasn't finding the apache library because I had to include that jar on the server... Thanks for helping everyone! :)

Similar Threads

  1. Replies: 14
    Last Post: 07-15-2011, 06:22 AM
  2. Replies: 1
    Last Post: 02-27-2010, 02:29 AM
  3. Replies: 9
    Last Post: 10-20-2009, 11:52 AM
  4. Replies: 3
    Last Post: 05-10-2009, 12:31 AM
  5. Replies: 9
    Last Post: 07-10-2008, 05:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •