aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes FTP with sun.net.ftp. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "FTP with sun.net.ftp." Watch "FTP with sun.net.ftp." New topic
Author

FTP with sun.net.ftp.

Avanish Raut
Greenhorn

Joined: Feb 20, 2001
Posts: 4
I am using BufferedInputStream and BufferedOutputStream to transfer files in batches of 1024 bytes since the file size varies from 1024Byes to 500MB.
BufferedOutputStream is unable to write if buffer size is less than 1024 bytes. It transfers files with zero bytes.
It is working fine for file size > 1024 bytes
Any help will be appreciated.


Ava
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
I'm not sure where your problem could be. I've used the same thing Sun's FtpClient, BufferOutputStream and successfully sent files as small as 64 bytes. Post a code example and we'll see if we can help.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Avanish Raut
Greenhorn

Joined: Feb 20, 2001
Posts: 4
Originally posted by Carl Trusiak:
I'm not sure where your problem could be. I've used the same thing Sun's FtpClient, BufferOutputStream and successfully sent files as small as 64 bytes. Post a code example and we'll see if we can help.

Here is the code, please let me know whats wrong with this code.

I added the UBB tags Code for easier reading. How to use UBB tags can be found Here
[This message has been edited by Carl Trusiak (edited February 22, 2001).]
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340

Wow, try simplifing this to:

That's about all I used and it worked fine.

[This message has been edited by Carl Trusiak (edited February 22, 2001).]
Avanish Raut
Greenhorn

Joined: Feb 20, 2001
Posts: 4
When I started, my code was like that way only. After that I observed that last 1024 bytes were not transfered properly. Thats the reason I changed my code like the way it is now.
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Like I said, I used the exact code I posted and had no problems. I have to caution on using Sun's FtpClient, it's an unsupported package and it could just be the version you are using. Try refactoring you code and include the Socket based FTPClient Jeff Holmes contributed. It's not fully complete but, should have enough for your task http://www.javaranch.com/ubb/Forum38/HTML/000066.html

------------------
Hope This Helps
Carl Trusiak
Jon House
Greenhorn

Joined: Jan 27, 2004
Posts: 1
Try adding the bout.flush to the portion of the code when there's less than 1024 bytes. See code below. I was having the same problem until I used the bout.flush(); to flush the buffer.

System.out.println("No of Bytes in file" + bReader.available());
byte[] buffer = new byte[bReader.available()];
int lastReadCount = bReader.read(buffer);
bout.write(buffer,0,lastReadCount);
total = total + lastReadCount;
bout.flush();
System.out.println(total);
 
jQuery in Action, 2nd edition
 
subject: FTP with sun.net.ftp.