commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zoran Jeremic <>
Subject Re: problem to create FTP client
Date Sat, 19 Apr 2008 12:45:04 GMT
Hi James,
  Thank you for your help. It works in this way you suggested me but if I set the bufferSize
on 10000. If I set it for example to 1000 I get black box instead of the class on class diagram
picture. I have tried it with very simple project and simple UML diagram. 
  Can you please explain me is there something like optimal buffersize for network trafic?
I'm not sure how big the project and picture uploaded this way could be, as it depends on
user, and maybe it can be very big.

James Carman <> wrote:
  Have you tried closing the output stream? Also, you might want to try
copying more than one byte at a time. I usually use a byte[] buffer:

public static void copy(InputStream in, OutputStream out, int
bufferSize) throws IOException
int bytesRead = -1;
final byte[] buffer = new byte[bufferSize];
while ((bytesRead = != -1)
out.write(buffer, 0, bytesRead);

Hope that helps!

On Sat, Apr 19, 2008 at 8:05 AM, Zoran Jeremic wrote:
> Hi,
> I'm using a commons-net to upload an ArgoUML project (archive with extension .zargo)
and its class diagram as picture (.png) to the remote FTP server. Its works fine in case FTP
client and FTP server are on the same PC. However, if the FTP client is on other PC it also
upload both files picture and project to the FTP repository but those files has only 1 kb
instead of 5 or more and are unreadable.
> Here is the code:
> public void createConnectionToFTPServer(String host,String username, String password){
> try{
> ftp.connect(host);
> ftp.login(username, password);
> int reply=ftp.getReplyCode();
> if(FTPReply.isPositiveCompletion(reply)){
>"Connected Successfully to the FTP server");
> }else{
>"Connection to the FTP server Failed");
> ftp.disconnect();
> }
> ...
> public void uploadFileToRepository(File file,String filename){
> try{
> ftp.setFileType(FTP.IMAGE_FILE_TYPE);
> InputStream fis = new FileInputStream(file);
> OutputStream os = ftp.storeFileStream(filename);
> int t=0;
> while( ( >=0){
> os.write(t);
> }
> }catch(IOException ioe){
> ...
> public void closeConnection(){
> try{
> ftp.disconnect();
> ....
> I hope that somebody has an idea what can be problem.
> Thanks
> Zoran
> ---------------------------------
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.

To unsubscribe, e-mail:
For additional commands, e-mail:

Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message