Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
4.8k views
in Java FTP by (160 points)
Hi,

the file = *.dbf
the size = 200MB
FTP Server = FileZilla Server (APPEND MODE)

i always got the file on the server (file size>200MB or too much or can't stop upload...)(dirty read?)
this is my code, have any problem?
thanks!


FileTransferClient ftp = new FileTransferClient();
ftp.setRemoteHost(host);
ftp.setRemotePort(21);
ftp.setTimeout(10000);
ftp.setUserName(user);
ftp.setPassword(password);

ftp.setContentType(FTPTransferType.BINARY);
ftp.connect();
.
.
.

try {
   if(ftp.exists(fileName)) {
             ftp.uploadFile(uFile.getPath(),fileName,WriteMode.APPEND);
   } else {
                 ftp.uploadFile(uFile.getPath(),fileName);
   }
                 
} catch (Exception e) {
             ftp.uploadFile(uFile.getPath(),fileName,WriteMode.APPEND);
}

3 Answers

0 votes
by (51.6k points)
Try using WriteMode.RESUME instead of WriteMode.APPEND.

To illustrate the difference, imagine that the content of your file is '0123456789' and that your previous attempt only uploaded '0123456'. If you use APPEND then you will get '01234560123456789' if the retry succeeds, whereas if you use RESUME then you'll get '0123456789'. In other words, APPEND restarts from the beginning and RESUME restarts from where you left off (as indicated by the size of the remote file).

Does that make sense?

- Hans (EnterpriseDT)
0 votes
by (160 points)
OK, I will try this solution about RESUME and APPEND.

But I have another question.
Once I try to write my RETRY CODE like this

inputStream.skip(ftp.size(fileName));
oOutput = new FTPOutputStream(ftp,fileName,true);


And the file on the server seem to correct.
Is my solution correct really?

if I use "oOutput = new FTPOutputStream(ftp,fileName,true);" before
I must use "inputStream.skip(ftp.size(fileName));" first?

Sorry, my English is bad.
Thanks your help!!


JERRY
0 votes
by (51.6k points)
Conceptually that is the same as using WriteMode.APPEND with FileTransferClient.uploadFile, but there may be some subtle differences. Please let us know if you find any problems.

- Hans (EnterpriseDT)

Categories

...