使用 FTPClient 传输 FTP 文件时出现错误

发布于 2024-11-24 02:54:11 字数 1487 浏览 1 评论 0原文

当 ftp 文件传输到其他机器时,我遇到以下异常。

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)

我用于 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", input) 行得到的上述异常。

我是否遗漏了什么,或者使用方式不正确。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

初雪 2024-12-01 02:54:11

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

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.

过期以后 2024-12-01 02:54:11

我想支持上述解决方案,但我还没有足够的声誉。
这终于救了我!

        ftps.setFileType(FTP.BINARY_FILE_TYPE);
        ftps.enterLocalPassiveMode();
        ftps.execPBSZ(0) ;
        ftps.execPROT("P") ;

顺便说一句,我的问题是“传输过程中连接被重置”。下面两个命令是我的关键命令。
ftps.execPBSZ(0) ;
ftps.execPROT("P") ;

I want to support above solution, however I don't have enough reputation yet.
That save me finally!

        ftps.setFileType(FTP.BINARY_FILE_TYPE);
        ftps.enterLocalPassiveMode();
        ftps.execPBSZ(0) ;
        ftps.execPROT("P") ;

By the way, my issue is "connection is reset during process of transfer". Below 2 commands are the key commands to me.
ftps.execPBSZ(0) ;
ftps.execPROT("P") ;

蓝海似她心 2024-12-01 02:54:11

根据我的经验,此错误是由于文件系统已满而引起的

For my experience, this error was caused because the filesystem was full

离笑几人歌 2024-12-01 02:54:11

如果通过 ftps 传输文件 0KB(示例 PDF 文件)时遇到问题,则必须强制使用被动模式并设置文件类型

            ftps.setFileType(FTP.BINARY_FILE_TYPE);
            ftps.enterLocalPassiveMode();
            ftps.execPBSZ(0) ;
            ftps.execPROT("P") ;

If you have problems with file 0KB (example PDF files) once tranfered by ftps you have to force Passive Mode and set File Type

            ftps.setFileType(FTP.BINARY_FILE_TYPE);
            ftps.enterLocalPassiveMode();
            ftps.execPBSZ(0) ;
            ftps.execPROT("P") ;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文