I am getting 500 as reply code when I try to delete a file from remote server using java FTPClient
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
add a comment |
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
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 theretrieveFileStream
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
add a comment |
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
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
java file ftp java-io ftp-client
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 theretrieveFileStream
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
add a comment |
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 theretrieveFileStream
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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