I am getting 500 as reply code when I try to delete a file from remote server using java FTPClient












0















When I try to delete a file using ftpclient I am getting reply code as 500. Can someone help me with the issue. As you can see in the commented section of the code I tried to move the file to other folder and I got the reply code as 500 as well.



public boolean sendFile(HttpResponse httpresponse, String accessionNumber)
throws Exception {
FTPClient ftpClient = null;
boolean fileUploadStatus = false;
InputStream inputStream = null;
try {
FTPSClient ftpClient = new FTPSClient(true);
String fileName = "SampletesterFileNine.pdf";
String remotePath = "/";
String tempFile = remotePath + fileName;
try {
ftpClient.connect(server, this.port);
} catch (Exception e) {
e.printstackTrace();
}
int reply = ftpClient.getReplyCode();
logger.info("Reply code connect :" + reply);
if (FTPReply.isPositiveCompletion(reply)) {
boolean login = ftpClient.login(userName, password);
if (login) {
if (ftps) {
((FTPSClient) ftpClient).execPROT("P");
}
logger.info("Logged in to ftp server with host " + server);
} else {
logger.info("login failed");
}
} else {
logger.info("login failed with exception");
}
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
logger.info("Checking whether file exists or not!!");
inputStream = ftpClient.retrieveFileStream(tempFile);
if(inputStream != null) {
logger.info("File already exists");
isFileExist = true;
String toPath = "/failed/SampletesterFileNine.pdf";
/*boolean renamed = ftpClient.rename(tempFile, toPath);
logger.info("replycode is : " + ftpClient.getReplyCode());
if(renamed) {
logger.info("file moved to failed folder successfully");
} else {
logger.info("failed while moving file to failed folder");
} */
boolean renamed = ftpClient.deleteFile(tempFile);
logger.info("replycode is : " + ftpClient.getReplyCode());
if(renamed) {
logger.info("file moved to failed folder successfully");
} else {
logger.info("failed while moving file to failed folder");
}
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
}
} catch(Exception e) {
throw e;
} finally {
try {
if(inputStream != null) {
inputStream.close();
}
} catch (Exception e) {
e.printstackTrace();
}
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (Exception e) {
e.printstackTrace();
}
}
return fileUploadStatus;
}









share|improve this question

























  • If it returns 500 you should be able to see a stack trace somewhere. Take a look at that and post it here. Otherwise we'll just be on a treasure hunt.

    – Federico klez Culloca
    Nov 23 '18 at 10:21











  • Do you get the same problem, if you remove the retrieveFileStream call?

    – Martin Prikryl
    Nov 23 '18 at 11:19











  • Yes @MartinPrikryl , even after removing retrieveFileStream call I am facing the same problem.

    – Kilarapu Yethendra
    Nov 23 '18 at 11:50











  • Then, it looks like 80% of your code is not relevant to your question. So please edit your question to show Minimal, Complete, and Verifiable example.

    – Martin Prikryl
    Nov 23 '18 at 11:53
















0















When I try to delete a file using ftpclient I am getting reply code as 500. Can someone help me with the issue. As you can see in the commented section of the code I tried to move the file to other folder and I got the reply code as 500 as well.



public boolean sendFile(HttpResponse httpresponse, String accessionNumber)
throws Exception {
FTPClient ftpClient = null;
boolean fileUploadStatus = false;
InputStream inputStream = null;
try {
FTPSClient ftpClient = new FTPSClient(true);
String fileName = "SampletesterFileNine.pdf";
String remotePath = "/";
String tempFile = remotePath + fileName;
try {
ftpClient.connect(server, this.port);
} catch (Exception e) {
e.printstackTrace();
}
int reply = ftpClient.getReplyCode();
logger.info("Reply code connect :" + reply);
if (FTPReply.isPositiveCompletion(reply)) {
boolean login = ftpClient.login(userName, password);
if (login) {
if (ftps) {
((FTPSClient) ftpClient).execPROT("P");
}
logger.info("Logged in to ftp server with host " + server);
} else {
logger.info("login failed");
}
} else {
logger.info("login failed with exception");
}
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
logger.info("Checking whether file exists or not!!");
inputStream = ftpClient.retrieveFileStream(tempFile);
if(inputStream != null) {
logger.info("File already exists");
isFileExist = true;
String toPath = "/failed/SampletesterFileNine.pdf";
/*boolean renamed = ftpClient.rename(tempFile, toPath);
logger.info("replycode is : " + ftpClient.getReplyCode());
if(renamed) {
logger.info("file moved to failed folder successfully");
} else {
logger.info("failed while moving file to failed folder");
} */
boolean renamed = ftpClient.deleteFile(tempFile);
logger.info("replycode is : " + ftpClient.getReplyCode());
if(renamed) {
logger.info("file moved to failed folder successfully");
} else {
logger.info("failed while moving file to failed folder");
}
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
}
} catch(Exception e) {
throw e;
} finally {
try {
if(inputStream != null) {
inputStream.close();
}
} catch (Exception e) {
e.printstackTrace();
}
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (Exception e) {
e.printstackTrace();
}
}
return fileUploadStatus;
}









share|improve this question

























  • If it returns 500 you should be able to see a stack trace somewhere. Take a look at that and post it here. Otherwise we'll just be on a treasure hunt.

    – Federico klez Culloca
    Nov 23 '18 at 10:21











  • Do you get the same problem, if you remove the retrieveFileStream call?

    – Martin Prikryl
    Nov 23 '18 at 11:19











  • Yes @MartinPrikryl , even after removing retrieveFileStream call I am facing the same problem.

    – Kilarapu Yethendra
    Nov 23 '18 at 11:50











  • Then, it looks like 80% of your code is not relevant to your question. So please edit your question to show Minimal, Complete, and Verifiable example.

    – Martin Prikryl
    Nov 23 '18 at 11:53














0












0








0


1






When I try to delete a file using ftpclient I am getting reply code as 500. Can someone help me with the issue. As you can see in the commented section of the code I tried to move the file to other folder and I got the reply code as 500 as well.



public boolean sendFile(HttpResponse httpresponse, String accessionNumber)
throws Exception {
FTPClient ftpClient = null;
boolean fileUploadStatus = false;
InputStream inputStream = null;
try {
FTPSClient ftpClient = new FTPSClient(true);
String fileName = "SampletesterFileNine.pdf";
String remotePath = "/";
String tempFile = remotePath + fileName;
try {
ftpClient.connect(server, this.port);
} catch (Exception e) {
e.printstackTrace();
}
int reply = ftpClient.getReplyCode();
logger.info("Reply code connect :" + reply);
if (FTPReply.isPositiveCompletion(reply)) {
boolean login = ftpClient.login(userName, password);
if (login) {
if (ftps) {
((FTPSClient) ftpClient).execPROT("P");
}
logger.info("Logged in to ftp server with host " + server);
} else {
logger.info("login failed");
}
} else {
logger.info("login failed with exception");
}
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
logger.info("Checking whether file exists or not!!");
inputStream = ftpClient.retrieveFileStream(tempFile);
if(inputStream != null) {
logger.info("File already exists");
isFileExist = true;
String toPath = "/failed/SampletesterFileNine.pdf";
/*boolean renamed = ftpClient.rename(tempFile, toPath);
logger.info("replycode is : " + ftpClient.getReplyCode());
if(renamed) {
logger.info("file moved to failed folder successfully");
} else {
logger.info("failed while moving file to failed folder");
} */
boolean renamed = ftpClient.deleteFile(tempFile);
logger.info("replycode is : " + ftpClient.getReplyCode());
if(renamed) {
logger.info("file moved to failed folder successfully");
} else {
logger.info("failed while moving file to failed folder");
}
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
}
} catch(Exception e) {
throw e;
} finally {
try {
if(inputStream != null) {
inputStream.close();
}
} catch (Exception e) {
e.printstackTrace();
}
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (Exception e) {
e.printstackTrace();
}
}
return fileUploadStatus;
}









share|improve this question
















When I try to delete a file using ftpclient I am getting reply code as 500. Can someone help me with the issue. As you can see in the commented section of the code I tried to move the file to other folder and I got the reply code as 500 as well.



public boolean sendFile(HttpResponse httpresponse, String accessionNumber)
throws Exception {
FTPClient ftpClient = null;
boolean fileUploadStatus = false;
InputStream inputStream = null;
try {
FTPSClient ftpClient = new FTPSClient(true);
String fileName = "SampletesterFileNine.pdf";
String remotePath = "/";
String tempFile = remotePath + fileName;
try {
ftpClient.connect(server, this.port);
} catch (Exception e) {
e.printstackTrace();
}
int reply = ftpClient.getReplyCode();
logger.info("Reply code connect :" + reply);
if (FTPReply.isPositiveCompletion(reply)) {
boolean login = ftpClient.login(userName, password);
if (login) {
if (ftps) {
((FTPSClient) ftpClient).execPROT("P");
}
logger.info("Logged in to ftp server with host " + server);
} else {
logger.info("login failed");
}
} else {
logger.info("login failed with exception");
}
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
logger.info("Checking whether file exists or not!!");
inputStream = ftpClient.retrieveFileStream(tempFile);
if(inputStream != null) {
logger.info("File already exists");
isFileExist = true;
String toPath = "/failed/SampletesterFileNine.pdf";
/*boolean renamed = ftpClient.rename(tempFile, toPath);
logger.info("replycode is : " + ftpClient.getReplyCode());
if(renamed) {
logger.info("file moved to failed folder successfully");
} else {
logger.info("failed while moving file to failed folder");
} */
boolean renamed = ftpClient.deleteFile(tempFile);
logger.info("replycode is : " + ftpClient.getReplyCode());
if(renamed) {
logger.info("file moved to failed folder successfully");
} else {
logger.info("failed while moving file to failed folder");
}
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
}
} catch(Exception e) {
throw e;
} finally {
try {
if(inputStream != null) {
inputStream.close();
}
} catch (Exception e) {
e.printstackTrace();
}
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (Exception e) {
e.printstackTrace();
}
}
return fileUploadStatus;
}






java file ftp java-io ftp-client






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 10:20









Federico klez Culloca

16.1k134380




16.1k134380










asked Nov 23 '18 at 10:18









Kilarapu YethendraKilarapu Yethendra

382




382













  • If it returns 500 you should be able to see a stack trace somewhere. Take a look at that and post it here. Otherwise we'll just be on a treasure hunt.

    – Federico klez Culloca
    Nov 23 '18 at 10:21











  • Do you get the same problem, if you remove the retrieveFileStream call?

    – Martin Prikryl
    Nov 23 '18 at 11:19











  • Yes @MartinPrikryl , even after removing retrieveFileStream call I am facing the same problem.

    – Kilarapu Yethendra
    Nov 23 '18 at 11:50











  • Then, it looks like 80% of your code is not relevant to your question. So please edit your question to show Minimal, Complete, and Verifiable example.

    – Martin Prikryl
    Nov 23 '18 at 11:53



















  • If it returns 500 you should be able to see a stack trace somewhere. Take a look at that and post it here. Otherwise we'll just be on a treasure hunt.

    – Federico klez Culloca
    Nov 23 '18 at 10:21











  • Do you get the same problem, if you remove the retrieveFileStream call?

    – Martin Prikryl
    Nov 23 '18 at 11:19











  • Yes @MartinPrikryl , even after removing retrieveFileStream call I am facing the same problem.

    – Kilarapu Yethendra
    Nov 23 '18 at 11:50











  • Then, it looks like 80% of your code is not relevant to your question. So please edit your question to show Minimal, Complete, and Verifiable example.

    – Martin Prikryl
    Nov 23 '18 at 11:53

















If it returns 500 you should be able to see a stack trace somewhere. Take a look at that and post it here. Otherwise we'll just be on a treasure hunt.

– Federico klez Culloca
Nov 23 '18 at 10:21





If it returns 500 you should be able to see a stack trace somewhere. Take a look at that and post it here. Otherwise we'll just be on a treasure hunt.

– Federico klez Culloca
Nov 23 '18 at 10:21













Do you get the same problem, if you remove the retrieveFileStream call?

– Martin Prikryl
Nov 23 '18 at 11:19





Do you get the same problem, if you remove the retrieveFileStream call?

– Martin Prikryl
Nov 23 '18 at 11:19













Yes @MartinPrikryl , even after removing retrieveFileStream call I am facing the same problem.

– Kilarapu Yethendra
Nov 23 '18 at 11:50





Yes @MartinPrikryl , even after removing retrieveFileStream call I am facing the same problem.

– Kilarapu Yethendra
Nov 23 '18 at 11:50













Then, it looks like 80% of your code is not relevant to your question. So please edit your question to show Minimal, Complete, and Verifiable example.

– Martin Prikryl
Nov 23 '18 at 11:53





Then, it looks like 80% of your code is not relevant to your question. So please edit your question to show Minimal, Complete, and Verifiable example.

– Martin Prikryl
Nov 23 '18 at 11:53












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53444766%2fi-am-getting-500-as-reply-code-when-i-try-to-delete-a-file-from-remote-server-us%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53444766%2fi-am-getting-500-as-reply-code-when-i-try-to-delete-a-file-from-remote-server-us%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy