10 Replies - 2016 Views - Last Post: 20 December 2009 - 02:35 PM Rate Topic: -----

#1 scottyadam  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 116
  • Joined: 03-December 07

Fastest FTP library

Posted 19 December 2009 - 05:24 AM

Ok, so here is my use.

I am going to have this java application that will be transferring up to 10 pictures (under 1.5MB each) in each session. The way I am doing it now with the simpleuploader by jibble...jeeze it is taking 10 minutes to upload a 2.1MB file and I am on a wireless connection here at home. I pulled up filezilla FTP client and it took about 30 seconds...this happens with like15K files that are taking way too long to upload.

Which library do i have to use so that I can get fast upload performance?

adam

Is This A Good Question/Topic? 0
  • +

Replies To: Fastest FTP library

#2 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Fastest FTP library

Posted 19 December 2009 - 11:04 AM

I personally have never had a use for FTP inside of Java, but this site seems to be helpful, as it compares various FTP libraries available for Java

Although, the page is from 2003, so it might not have the latest and greatest libraries.
Was This Post Helpful? 0
  • +
  • -

#3 scottyadam  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 116
  • Joined: 03-December 07

Re: Fastest FTP library

Posted 19 December 2009 - 11:41 AM

View Posterik.price, on 19 Dec, 2009 - 10:04 AM, said:

I personally have never had a use for FTP inside of Java, but this site seems to be helpful, as it compares various FTP libraries available for Java

Although, the page is from 2003, so it might not have the latest and greatest libraries.


thx eric.price for the response..ya i had a look at that site as well as a newer one by it's author...i am stilling going through the the libraries so far encountered a bug with commons (i believe), still slow with Jscape and simpleuploader by jibble....kinda sucks...too bad...

adam
Was This Post Helpful? 0
  • +
  • -

#4 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Fastest FTP library

Posted 19 December 2009 - 04:27 PM

Well, if you really wanted to, you could create your own library! :D
Was This Post Helpful? 0
  • +
  • -

#5 scottyadam  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 116
  • Joined: 03-December 07

Re: Fastest FTP library

Posted 19 December 2009 - 04:29 PM

View Posterik.price, on 19 Dec, 2009 - 03:27 PM, said:

Well, if you really wanted to, you could create your own library! :D


That is very true...now what would the fastest library be...i have a feeling the one that I am using transfers byte by byte...I am only starting to get into this...what would be a faster method...is there one?
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Fastest FTP library

Posted 19 December 2009 - 07:26 PM

Java API has all the FTPxxx classes free to use
Unless you are really lazy and do not want to code it with the standard API why would you use a third party one ?
Was This Post Helpful? 0
  • +
  • -

#7 scottyadam  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 116
  • Joined: 03-December 07

Re: Fastest FTP library

Posted 20 December 2009 - 10:34 AM

It isn't that I am really lazy, it is the fact that i am quite inexperienced with writing my own ala momento :)

so lets just say i were to write my own...I dunno if this is right or wrong but I have been hearing that transferring byte by byte is insanely slow. Is there a faster way? Also, could the Task() that I am using (which i got to work by the way) be slowing anything down?

Really appreciate the help thus far and hope I can nail this defect down soon.

This post has been edited by scottyadam: 20 December 2009 - 10:35 AM

Was This Post Helpful? 0
  • +
  • -

#8 vasdueva  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 141
  • Joined: 03-April 07

Re: Fastest FTP library

Posted 20 December 2009 - 01:21 PM

Instead of doing it byte by byte, couldn't you somehow buffer it(almost like a reader or writer).
Was This Post Helpful? 0
  • +
  • -

#9 scottyadam  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 116
  • Joined: 03-December 07

Re: Fastest FTP library

Posted 20 December 2009 - 01:26 PM

anyone have a small example...cause I am not following...:(
Was This Post Helpful? 0
  • +
  • -

#10 redhotfire0  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 210
  • Joined: 13-July 09

Re: Fastest FTP library

Posted 20 December 2009 - 02:29 PM

You will need to know much more then putting data into a buffer. Have you thought of how you are going to transfer the information? If not, follow pbl advice and use the API instead of third party extensions.
Was This Post Helpful? 0
  • +
  • -

#11 scottyadam  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 116
  • Joined: 03-December 07

Re: Fastest FTP library

Posted 20 December 2009 - 02:35 PM

View Postredhotfire0, on 20 Dec, 2009 - 01:29 PM, said:

You will need to know much more then putting data into a buffer. Have you thought of how you are going to transfer the information? If not, follow pbl advice and use the API instead of third party extensions.


well i have a fully working application right now using SimpleFTP that I modified slightly to work with my ftp server which is here:

I believe this uses the java api?

SimpleFTP modified version:
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.JPanel;
public class SimpleFTP extends JPanel {
		private Socket socket;
	private BufferedReader reader;
	private BufferedWriter writer;

	private static boolean DEBUG;
	
	/**
	 * Create an instance of SimpleFTP.
	 */
	public SimpleFTP() {
		socket = null;
		reader = null;
		writer = null;
		DEBUG = false;
	}
	
	
	/**
	 * Connects to the default port of an FTP server and logs in as
	 * anonymous/anonymous.
	 */
	public synchronized void connect(String host) throws IOException {
		connect(host, 21);
	}
	
	
	/**
	 * Connects to an FTP server and logs in as anonymous/anonymous.
	 */
	public synchronized void connect(String host, int port) throws IOException {
		connect(host, port, "anonymous", "anonymous");
	}
	
	
	/**
	 * Connects to an FTP server and logs in with the supplied username
	 * and password.
	 */
	public synchronized void connect(String host, int port, String user, String pass) throws IOException {
		//while(true){
			//JOptionPane.showMessageDialog(this, "time");
		if (socket != null) {
			throw new IOException("SimpleFTP is already connected. Disconnect first.");
		}
		socket = new Socket(host, port);
		reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
		String response;
		while (true){
			response = readLine();
			if(response.equals("220 You will be disconnected after 15 minutes of inactivity."))
			{break;}
		}
		
		if (!response.startsWith("220")) {
			throw new IOException("SimpleFTP received an unknown response when connecting to the FTP server: " + response);
		}
		
		sendLine("USER " + user);
		
		response = readLine();
		if (!response.startsWith("331")) {
			throw new IOException("SimpleFTP received an unknown response after sending the user: " + response);
		}
		
		sendLine("PASS " + pass);
		
		response = readLine();
		if (!response.startsWith("230")) {
			throw new IOException("SimpleFTP was unable to log in with the supplied password: " + response);
		}else{
			//break;
		//}
		
		// Now logged in.
	}}
	
	
	/**
	 * Disconnects from the FTP server.
	 */
	public synchronized void disconnect() throws IOException {
		try {
			sendLine("QUIT");
		}
		finally {
			socket = null;
		}
	}
	
	
	/**
	 * Returns the working directory of the FTP server it is connected to.
	 */
	public synchronized String pwd() throws IOException {
		sendLine("PWD");
		String dir = null;
		String response = readLine();
		if (response.startsWith("257 ")) {
			int firstQuote = response.indexOf('\"');
			int secondQuote = response.indexOf('\"', firstQuote + 1);
			if (secondQuote > 0) {
				dir = response.substring(firstQuote + 1, secondQuote);
			}
		}
		return dir;
	}


	/**
	 * Changes the working directory (like cd). Returns true if successful.
	 */   
	public synchronized boolean cwd(String dir) throws IOException {
		sendLine("CWD " + dir);
		String response = readLine();
		return (response.startsWith("250 "));
	}
	
	
	/**
	 * Sends a file to be stored on the FTP server.
	 * Returns true if the file transfer was successful.
	 * The file is sent in passive mode to avoid NAT or firewall problems
	 * at the client end.
	 */
	public synchronized boolean stor(File file) throws IOException {
		if (file.isDirectory()) {
			throw new IOException("SimpleFTP cannot upload a directory.");
		}
		
		String filename = file.getName();

		return stor(new FileInputStream(file), filename);
	}

	public synchronized void getcommand(){

	}
	
	/**
	 * Sends a file to be stored on the FTP server.
	 * Returns true if the file transfer was successful.
	 * The file is sent in passive mode to avoid NAT or firewall problems
	 * at the client end.
	 */
	public synchronized boolean stor(InputStream inputStream, String filename) throws IOException {

		BufferedInputStream input = new BufferedInputStream(inputStream);
		//JOptionPane.showMessageDialog(this, "got here");
		sendLine("PASV");
		String response = readLine();
		//JOptionPane.showMessageDialog(this, "1"+response);
		response = readLine();
	   // JOptionPane.showMessageDialog(this, "2"+response);
		//while(! response.startsWith("227")){
			
		//JOptionPane.showMessageDialog(this, "3"+response);//sendLine("PASV");
		//}
		if (!response.startsWith("227")) {
			throw new IOException("SimpleFTP could not request passive mode: " + response);
		}
		
		String ip = null;
		int port = -1;
		int opening = response.indexOf('(');
		int closing = response.indexOf(')', opening + 1);
		if (closing > 0) {
			String dataLink = response.substring(opening + 1, closing);
			StringTokenizer tokenizer = new StringTokenizer(dataLink, ",");
			try {
				ip = tokenizer.nextToken() + "." + tokenizer.nextToken() + "." + tokenizer.nextToken() + "." + tokenizer.nextToken();
				port = Integer.parseInt(tokenizer.nextToken()) * 256 + Integer.parseInt(tokenizer.nextToken());
			}
			catch (Exception e) {
				throw new IOException("SimpleFTP received bad data link information: " + response);
			}
		}
		
		sendLine("STOR " + filename);
		
		Socket dataSocket = new Socket(ip, port);
		
		response = readLine();
		if (!response.startsWith("150")) {
			throw new IOException("SimpleFTP was not allowed to send the file: " + response);
		}
		
		BufferedOutputStream output = new BufferedOutputStream(dataSocket.getOutputStream());
		byte[] buffer = new byte[4096];
		int bytesRead = 0;
		while ((bytesRead = input.read(buffer)) != -1) {
			output.write(buffer, 0, bytesRead);
		}
		output.flush();
		output.close();
		input.close();
		
		response = readLine();
		return response.startsWith("226");
	}


	/**
	 * Enter binary mode for sending binary files.
	 */
	public synchronized boolean bin() throws IOException {
		sendLine("TYPE I");
		String response = readLine();
		return (response.startsWith("200 "));
	}
	
	
	/**
	 * Enter ASCII mode for sending text files. This is usually the default
	 * mode. Make sure you use binary mode if you are sending images or
	 * other binary data, as ASCII mode is likely to corrupt them.
	 */
	public synchronized boolean ascii() throws IOException {
		sendLine("TYPE A");
		String response = readLine();
		return (response.startsWith("200 "));
	}
	
	
	/**
	 * Sends a raw command to the FTP server.
	 */
	private void sendLine(String line) throws IOException {
		if (socket == null) {
			throw new IOException("SimpleFTP is not connected.");
		}
		try {
			writer.write(line + "\r\n");
			writer.flush();
			if (DEBUG) {
				System.out.println("> " + line);
			}
		}
		catch (IOException e) {
			socket = null;
			throw e;
		}
	}
	
	private String readLine() throws IOException {
		String line = reader.readLine();
		if (DEBUG) {
			System.out.println("< " + line);
		}
		return line;
	}
	
	
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1