Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftp server

Status
Not open for further replies.

liorza

Programmer
Mar 3, 2004
27
US
Anyone can recommend an opens source easy to use ftp server application to be use under tomcat?

Lior
 
There's a few :


or type "java ftp" in google.

Or you could write your won, here is a example to get you started off :

Code:
import sun.net.ftp.*;
import sun.net.*;
import java.io.*;


public class Ftp {
	public static void main(String args[]) throws Exception {
		// Conatct server and log in
		String server = "bridport";
		String user = "joeblogs";String passwd = "abcdefg";//
		FtpClient client = new FtpClient();
		System.err.println("Opening server ...");
		client.openServer(server);
		System.err.println("Logging in...");
		client.login(user, passwd);
		System.err.println("Changing to binary ...");
		client.binary();//
		client.cd("transfer");

		// pwd
		String pwd = client.pwd();
		System.err.println(pwd);

		// list dir
		TelnetInputStream in = client.list();
		BufferedOutputStream bos = new BufferedOutputStream(System.err);
		int buffer = 0;
		while ((buffer = in.read()) != -1) {
			bos.write(buffer);
		}

		bos.flush();
		bos.close();
		in.close();

		// Get a file
		in = client.get("floodmap.png");
		bos = new BufferedOutputStream(new FileOutputStream("C:/floodmap2.png"));
		buffer = 0;
		while ((buffer = in.read()) != -1) {
			bos.write(buffer);
		}

		bos.flush();
		bos.close();
		in.close();

		// Send a file
		TelnetOutputStream out = client.put("floodmap.png");
		File file = new File("C:/floodmap.png");
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
		byte[] b = new byte[(int)file.length()];
		bis.read(b);
		out.write(b);

		out.flush();
		out.close();
		bis.close();


		client.closeServer();


	}
}
 
hi,

these pages dont have library you used i.e. sun.net.*

from where i can have that??
 
sun.net package is not part of the standard SDK, but is part of Sun's own JRE implementation - so they are unsupported and undocumented, but you can still use them.

--------------------------------------------------
Free Database Connection Pooling Software
 
Well no, beause FTP is not HTTP - they are completely differerent protocols.

So your server String must be like :

String server = "serverName";

Plus you obviously must have a FTP server daemon running ...

--------------------------------------------------
Free Database Connection Pooling Software
 
hi,
so, it implies i cant use tomcat as ftp server. is there any method!!
 
Tomcat is a servlet container that can handle HTTP requests. HTTP is a protocol for sending requests for data and transmitting that data over a socket. FTP is a protocol for sending requests to send and retrieve data and transmitting that data over a socket, but it is a different protocol than HTTP.

There are FTP servers written in java, and there are HTTP servers not written in java, they are two different animals. It would be far simpler to install an FTP server on your box.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top