Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FTP with sun.net.ftp.

 
Avanish Raut
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Avanish Raut
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic