M.J. M.J. - 1 month ago 26
Java Question

Getting an error while FTP file using FTPClient

I am getting following exception while ftp file over to some other machine.

org.apache.commons.net.io.CopyStreamException: IOException caught while copying.
at org.apache.commons.net.io.Util.copyStream(Util.java:119)
at org.apache.commons.net.io.Util.copyStream(Util.java:151)
at org.apache.commons.net.io.Util.copyStream(Util.java:162)
at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:373)
at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1360)
at com.fs.ftp.FTPUsingFTPClientApache.startFTP(FTPUsingFTPClientApache.java:40)
at com.fs.ftp.FTPUsingFTPClientApache.main(FTPUsingFTPClientApache.java:17)


The Code that i am using for FTP is something like :-

FTPClient ftpClient = new FTPClient();
ftpClient.connect("home.abc.com");
ftpClient.login("remote", "guesst12");
int replyCode = ftpClient.getReplyCode();
if(FTPReply.isPositiveCompletion(replyCode)) {
System.out.println("Connection proper");
}

if(ftpClient.changeWorkingDirectory("share")) {
System.out.println("Directory Change Succesfull");
}
InputStream input = new FileInputStream(new File("H:/testFile.txt"));
BufferedInputStream inputStrean = new BufferedInputStream(input);
if(ftpClient.storeFile("testFile.txt", input)) {
System.out.println("File Stored Successfully");
}
input.close();
inputStrean.close();
ftpClient.logout();
ftpClient.disconnect();


The above exception i get at line
ftpClient.storeFile("testFile.txt", input)
.

Am i missing something, or using it not the correct way.

Thanks

Answer

Catch that exception, call its getIOException() method to get the exception that caused the problem, an print its stacktrace. That will tell you what IOException caused the copy to fail.

Comments