Home arrow static arrow Java Programming [Archive] - problem upload file with ftp
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - problem upload file with ftp
This topic has 3 replies on 1 page.

Posts:16
Registered: 6/23/04
problem upload file with ftp  
Jul 22, 2004 9:05 AM



 
Hi,

I'd like to upload a file with an ftp. I declared a method using an url as follow :

public static void uploadFile(File fileToMove_p, String newFileName_p) {
try {
URL url_l = new URL("ftp://[uid]:[pwd]@localhost/" + newFileName_p);
URLConnection connection_l = url_l.openConnection();
OutputStream output_l = connection_l.getOutputStream();

BufferedOutputStream bos = new BufferedOutputStream(output_l);
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileToMove_p));
int i;
while ((i = bis.read()) != -1) {
bos.write(i);
}
}
catch (IOException ex) {}
}

But when I oppen my new file, it miss the end of my data. The ftp cut the few last line of my original file.
Any idear of what is happening here and how I can solve the problem ?

Thanks
 

Posts:1,995
Registered: 12/10/00
Re: problem upload file with ftp  
Jul 22, 2004 9:08 AM (reply 1 of 3)



 
Try calling bos.flush() after the read/write loop

HTH
Mike
 

Posts:16
Registered: 6/23/04
Re: problem upload file with ftp  
Jul 22, 2004 9:12 AM (reply 2 of 3)



 
ok I'm stupid. Thanks a lot it works well now.
 

Posts:24,036
Registered: 2/3/03
Re: problem upload file with ftp  
Jul 22, 2004 10:04 AM (reply 3 of 3)



 
Are you closing the OutputStream? If not, you probably should, and closing the stream will flush it prior to closing.

HTH,
§
 
This topic has 3 replies on 1 page.