aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes FTP Dowload JPG & XML files only... USing com.oroinc.net.ftp.*   from  FTP server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "FTP Dowload JPG & XML files only... USing com.oroinc.net.ftp.*   from  FTP server" Watch "FTP Dowload JPG & XML files only... USing com.oroinc.net.ftp.*   from  FTP server" New topic
Author

FTP Dowload JPG & XML files only... USing com.oroinc.net.ftp.* from FTP server

Kondal reddy
Greenhorn

Joined: Sep 23, 2003
Posts: 22
Hi guys I am trying to download JPG and XML files from my FTP server...using down code ....

import java.io.*;
import java.util.*;
import com.oroinc.net.ftp.*;
import com.oroinc.net.*;

public class IMG_ejbLOAD_IMGBean implements javax.ejb.SessionBean {
private javax.ejb.SessionContext mySessionCtx;

static String server = "192.168.1.129";
static int port = 21;
static String id = "jkreddy";
static String password= "jkreddy";


FTPClient ftpClient = new FTPClient();

public boolean login(String user, String password) {
try {
this.id = user;
this.password = password;
this.connect();
return ftpClient.login(user, password);
}
catch (IOException ioe) {
ioe.printStackTrace();
}
return false;
}

public boolean logout() {
try {
return ftpClient.logout();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
return false;
}

public void connect() {
try {
System.out.println("server="+server);
System.out.println("port="+port);
ftpClient.connect(server, port);

System.out.println("after connection = "+port);
int reply;

reply = ftpClient.getReplyCode();
System.out.println("reply = "+reply);
if(!FTPReply.isPositiveCompletion(reply)) {
ftpClient.disconnect();
System.err.println("Connection problem");
System.exit(1);
}
ftpClient.login("jkreddy", "jkreddy");
FTPFile[] files = list();
File fileout = null;


for (int i = 0; i < files.length ; i++) {
String fileName = files[i].getName();

String extension = fileName.substring(fileName.lastIndexOf(".") + 1);

System.out.println("fileName = "+fileName);
System.out.println("in ejb fileName length = "+fileName.length());
long size = files[i].getSize();
System.out.println("in ejb file[i] size = "+size);


if ( (size > 0) && ((extension.equalsIgnoreCase("jpg"))||(extension.equalsIgnoreCase("xml")) )) {

System.out.println("inside extension filter //////"+fileName);
System.out.println("ftpClient "+ftpClient);
fileout = get(fileName, "C:/jk1/jk.jpg");
//ftpClient.retrieveFile(fileName, fos);
System.out.println("inside ejb jpg file *** .... "+fileout);
//System.out.println("inside ejb jpg file lenth *** .... "+fileout.length());
//lObjRemote.put("c://jk.jpg","");
}


}
}
catch (IOException ioe) {
if(ftpClient.isConnected()) {
try {
ftpClient.disconnect();
} catch(IOException f) {
//
}
}
System.err.println("Connection problem 2");
System.exit(1);
}
}


public FTPFile[] list() {
FTPFile[] files = null;
try {
files = ftpClient.listFiles();
System.out.println("inside ftp files.... = "+files);
return files;
}
catch (IOException ioe) {
ioe.printStackTrace();
}
return files;
}

public File get(String source, String target) {
OutputStream output = null;
File file = null;
try {
System.out.println("inside ..file.get...1....");
File local = new File(target);
System.out.println("local = "+local);
output = new FileOutputStream(local);
System.out.println("output = "+output);
}
catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
}
System.out.println("source = "+source);

try {
System.out.println("inside ..file.get...2....ftpclient "+ftpClient);
System.out.println("ftpClient.retrieveFile(source, output) "+ftpClient.retrieveFile(source, output));
output.close();
file = new File(target);
System.out.println("filexxxxxx = "+file);
return file;
/*if () {

}*/
}
catch (IOException ioe) {
System.out.println("Error while retrieve file "+ioe);
}
return null;
}


public String put(String source, String target)
{
InputStream input = null;
try {
File local = new File(source);
input = new FileInputStream(local);
}
catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
}
try
{
ftpClient.storeFile(target,input);
return "SUCCESS";
}
catch (Exception e)
{
e.printStackTrace();
return "FAIL";
}
}

public void disconnect() {
try {
ftpClient.disconnect();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}

if I run this code I could not storing my jpg file to my temperary path .............

in my System.out.println s getting my JPG file after filtering....

....inside extension filter //////Bluehills.jpg.... is my print out put... but ...another print out put...is ...
....ftpClient.retrieveFile(source, output) false...


any body can help ...why my ftpClient.retrieveFile(source, output) false...giving false and not downloading....
[ October 17, 2005: Message edited by: Kondal reddy ]
Kondal reddy
Greenhorn

Joined: Sep 23, 2003
Posts: 22
no one reply...is it loking big? ....
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8718
    
    6

Hey Kondal, there's a couple of reason you aren't getting any replies. First, yes, your code is a little long.
Another reason may be that your code is an EJB. That's a lot of time for us to invest in getting your code to run, compiling and deploying and so on.
Third, your code uses this third party library, com.oroinc.net.ftp, that we'd have to hunt down and install.
Your best bet to get help is to write a small stand-alone program which exhibits the problem you are having. If you want to use a third party library, there's probably a user group or mailing list that supports it.
You'll get the most help here if you use the standard J2SE API (supports FTP) or popular open source packages like Jakarta Commons Net.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FTP Dowload JPG & XML files only... USing com.oroinc.net.ftp.* from FTP server
 
Similar Threads
Apache Commons FTPClient not wokring in Red Hat Linux
FTP problem with commons.net.ftp.FTPClient
FTP problem in commons.net.ftp.FTPCient
FTPClient : is not working
FTP problem in commons.net.ftp.FTPClient