简体   繁体   中英

Error while uploading file to file server

I am getting an error while running a code which uploads a file to file server. I am using Apache Commons Net File client to transfer the file. I want to upload a image file. As it was not working, I tried with a text file and still I get the same error.

Find below my code:

    FTPClient clientFtp = new FTPClient();

    clientFtp.setFileType(FTP.BINARY_FILE_TYPE);
    clientFtp.setFileTransferMode(FTP.BINARY_FILE_TYPE);
    clientFtp.setSoTimeout(10000);
    clientFtp.enterLocalPassiveMode();
    result = clientFtp.storeFile("test", fs);

Error I am getting is:

Exception in thread "main" java.lang.NoSuchFieldError: _socketFactory_
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:513)
at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:388)
at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1388)
at sampe.test.files.Test.main(Test.java:95)

I checked the file server log to get some more information and I found this:

(000028)8/16/2014 17:14:20 PM - root (127.0.0.1)> MODE N

(000028)8/16/2014 17:14:20 PM - root (127.0.0.1)> 504 Unknown MODE type

(000028)8/16/2014 17:14:20 PM - root (127.0.0.1)> PASV

(000028)8/16/2014 17:14:20 PM - root (127.0.0.1)> 227 Entering Passive Mode (127,0,0,1,199,159)

(000028)8/16/2014 17:14:20 PM - root (127.0.0.1)> disconnected.

So, according to the file server log I feel that the error is in this following line:

clientFtp.setFileTransferMode(FTP.BINARY_FILE_TYPE);

Is there anything wrong in this code? I changed this file type to different ones and still this file type is not taken properly. This may be not an issue with Java code too. Maybe file server or Windows have a part on this?

When I changed the mode to:

clientFtp.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);

the log is:

(000030)8/16/2014 18:04:00 PM - root (127.0.0.1)> TYPE I

(000030)8/16/2014 18:04:00 PM - root (127.0.0.1)> 200 Type set to I

(000030)8/16/2014 18:04:00 PM - root (127.0.0.1)> MODE S

(000030)8/16/2014 18:04:00 PM - root (127.0.0.1)> 200 MODE set to S.

(000030)8/16/2014 18:04:00 PM - root (127.0.0.1)> PASV

(000030)8/16/2014 18:04:00 PM - root (127.0.0.1)> 227 Entering Passive Mode (127,0,0,1,202,181)

(000030)8/16/2014 18:04:01 PM - root (127.0.0.1)> disconnected.

For other 2 I got log as:

(000032)8/16/2014 18:05:31 PM - root (127.0.0.1)> 502 Unimplemented MODE type

The transfer mode should be one of the following: STREAM_TRANSFER_MODE (default), BLOCK_TRANSFER_MODE or COMPRESSED_TRANSFER_MODE .

Remove clientFtp.setFileTransferMode(FTP.BINARY_FILE_TYPE) and it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM