• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

FTP copying file with reduced to zero size.

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The function down allows connectar in another servant and to copy a file,
only that the copy this with reduced to zero size. What done this miss?
import java.io.*;
import com.oroinc.net.ftp.*;
public final class FTP {
public static final void main(String[] args) {
FTPClient client;
client = new FTPClient();
try {
client.connect("ftp.javasoft.com");
if(!FTPReply.isPositiveCompletion(client.getReplyCode())) {
client.disconnect();
System.err.println("FTP server refused connection.");
return;
}
client.login("anonymous", "user@hostname");
client.retrieveFile("c:/user/back2a.gif", new FileOutputStream("e:/temp/back2a.gif"));
client.quit();
client.disconnect();
}
catch(IOException e) {
e.printStackTrace();
}
}
}
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The documentation for FTPClient specifically says that retrieveFile() does not close the OutputStream you give it. That's your job:
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

import java.io.*;
import com.oroinc.net.ftp.*;
public final class FTPx {
public static final void main(String[] args) {
FTPClient client;
client = new FTPClient();
try {
client.connect("192.108.10.56");
client.login("sa","sa");
String local = args[0];
String remote = args[1];

OutputStream output;
output = new FileOutputStream(local);
client.retrieveFile(remote, output);
output.close();
client.quit();
client.disconnect();
}
catch(IOException e) {
e.printStackTrace();
}
}
}
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I continue with the problem of it copies of reduced to zero file. Even with the new source (according to source above)
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Strange. Try breaking the process into smaller parts and putting in print statements to report on the progress of each part:

Looking at the output of this, you can get a better idea exactly what is happening (and what isn't). Are any bytes being read at all?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim Yingst, I thank for his/her help. With the script that you sent me, I located the problem, but I still didn't solve the problem.
The mistake this happening as it tries to attribute the "length = input.read(buffer); " in the first time of the loop.

I still didn't find the definitive solution. In case you have an idea, please find out.

Once again thankful for the help.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim Yingst, I thank for his/her help
"His", please. You're welcome.
Well, what exactly happens? Does it read the length as -1? Does it throw an exception?
It's possible the FTPClient code is buggy; I've never used it, so I don't know. People seem happy with other ORO Software products, so I gather they're pretty good in general. But I dunno in this case.
Have you tried using the java.net.URL class instead? It should work with an "ftp://" protocol in place of the usual "http://". Then use openStream() to get an input stream from the named URL. I haven't used these classes much either, but since they're part of the standard Java SDK I expect them to work in most cases. Worth a try anyway if you can't get the FTPClient to work.
[ August 17, 2002: Message edited by: Jim Yingst ]
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also worth exploring:

This could provide more clues about whether FTPClient thinks there's really a file there or not, and how many bytes it has.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get the same problem and I find "ftp.retrieveFile(file.getName(),fos)"
return false. why?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get the same error.
"ftp.retrieveFile(file.getName(),fos)"
return false. Don't know why? the file transfered is 0 bytes.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Did anyone of you find what the cause is?

I am also getting problem with ftp.retreiveFile().

Thank you
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic