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 = in.read(buffer)) != -1)
{
out.write(buffer, 0, bytesRead);
}
}
Hope that helps!
On Sat, Apr 19, 2008 at 8:05 AM, Zoran Jeremic <[EMAIL PROTECTED]> 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)){
> LOG.info("Connected Successfully to the FTP server");
> }else{
> LOG.info("Connection to the FTP server Failed");
> ftp.disconnect();
> }
> ...
> public void uploadFileToRepository(File file,String filename){
> try{
> ftp.setFileType(FTP.IMAGE_FILE_TYPE);
> LOG.info("uploadFileToRepository");
> InputStream fis = new FileInputStream(file);
> OutputStream os = ftp.storeFileStream(filename);
> int t=0;
> while( (t=fis.read()) >=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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]