使用FTPClient在FTP文件中获取错误 [英] Getting an error while FTP file using FTPClient

查看:432
本文介绍了使用FTPClient在FTP文件中获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  org.apache.commons.net.io .CopyStreamException:复制时捕获IOException。 
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)
在我的代码中,我使用了一个代码,我使用的FTP类似于: - $ / $>

  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();

上面的例外我在 ftpClient.storeFile(testFile.txt ),输入)



我缺少什么东西,或者使用它的方式不正确。



Thanks

解决方案

捕获该异常,调用它的 getIOException()方法来获得导致问题的异常,打印它的堆栈跟踪。这会告诉你什么 IOException 导致复制失败。


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

解决方案

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.

这篇关于使用FTPClient在FTP文件中获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆