Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jtalerico

macrumors 6502
Original poster
Nov 23, 2005
358
0
Hey guys I am trying to get my Java code to connect via FTP to my site, and upload a file. Not sure how this will work. This is what i have so far!

Code:
            String wsave = JOptionPane.showInputDialog(null, "File Saved! Would you like to upload it?");
            if(wsave.equals("yes") || wsave.equals("y")) {
                URL site = new URL("ftp://MYUSER:*******@ftp://69.68.181.132/Sites/txt/; type=i");
                URLConnection conn = site.openConnection();
                File output = new File("ftp://69.68.181.132/Sites/txt/");
                Writer saveSite = new BufferedWriter(new FileWriter(output+input));
                saveSite.write(text);
                save.close();
                conn = null;
            }
        }

And i am catching the exception, so i am always getting File could not be written... Is there a way to "upload" or BufferedWriter the file on the server? Thanks!
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Opening a connection via the site.openConnection does not have any effect on other classes. So you cannot do that then expect that creating a File with the same address will work. It won't. You will need to do something directly with the URLConnection. What I don't know: I haven't read the documentation.
 

jtalerico

macrumors 6502
Original poster
Nov 23, 2005
358
0
These are the errors i am getting now...


2006-02-04 16:13:23.048 java[4201] CFLog (0): CFMessagePort: bootstrap_register(): failed 1103 (0x44f), port = 0x11f03, name = 'java.ServiceProvider'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2006-02-04 16:13:23.051 java[4201] CFLog (99): CFMessagePortCreateLocal(): failed to name Mach port (java.ServiceProvider)

Here is the new code...

Code:
            if(wsave.equals("yes") || wsave.equals("y")) {
                System.out.println("end");
                URL site = new URL("ftp://xxxxx:xxxxxx@ftp://192.168.0.22/Sites/txt/; type=i");
                URLConnection conn = site.openConnection();
                File output = new File(input);
                BufferedOutputStream os = new BufferedOutputStream(conn.getOutputStream());
                System.out.println("end");
                FileOutputStream in = new FileOutputStream(input);
                os.close();
 

jtalerico

macrumors 6502
Original poster
Nov 23, 2005
358
0
Fixed thanks. just changed it :)

Damn what a day... And thoughts on what is wrong?
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
jtalerico said:
thoughts on what is wrong?
nah, i haven't done java in 6 years and even then i never messed with connecting to an ftp server. however, a quick google search for java and ftp found this promising page.
 

jtalerico

macrumors 6502
Original poster
Nov 23, 2005
358
0
i have put the .jar file into my classpath and i still cannot get the thing to compile with this line....

import org.apache.commons.net.*;
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
jtalerico said:
i have put the .jar file into my classpath and i still cannot get the thing to compile with this line....

import org.apache.commons.net.*;

Then it's not in the classpath. How are you trying to compile?

Also, did you extract the .jar file from the .zip file you downloaded from Apache?
 

jtalerico

macrumors 6502
Original poster
Nov 23, 2005
358
0
yes, i extracted the jar file from the tar.gz...

I put the file into the /System/Lib.../Framework/JavaVM..../1.4.2/Classes/

That should be the classpath...

BTW Thanks for the help! :)
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
I would NOT suggest putting jar files there, instead learn to use the -classpath flag of the javac command. If you are using an IDE, they usually have a similar way to setup the classpath. For example, in Eclipse you can add .jar files as Libraries to a project's build path which for compilation purposes will include the .jar when you try to compile.

So again, how are you trying to compile this class(es)?
 

jtalerico

macrumors 6502
Original poster
Nov 23, 2005
358
0
Okay, i got all that worked out!! Thanks guys! Once again you guys are the greatest!!

But one more question!!!

Say i have a password field, and they are entering it in a JOptionPane.. I would like it to be **** instead of the plane text.. How do I do so? Thanks again guys!
 

jtalerico

macrumors 6502
Original poster
Nov 23, 2005
358
0
Yup, already got it.. I was hoping there was some sort of field you could put for Joptionpane because i am not that conserend with security....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.