Apache commons-net FTP - 将文件上传到安全 FTP IIS

发布于 2024-12-22 19:11:54 字数 1716 浏览 4 评论 0原文

我正在尝试使用 Apache commons-net FTP 库将大文件(>100Mb)上传到安全 FTP 服务器 IIS。

这是我的代码:

try{
ftpClient = new FTPSClient("TLS", false);
        this.ftpClient.setDataTimeout(6000000);
        this.ftpClient.setConnectTimeout(6000000);
        ftpClient.connect(host, port);
        ftpClient.login(userName, password);
            ftpClient.enterLocalPassiveMode();
         if (ftpClient.getReplyCode() == 230){
               ftpClient.sendCommand("OPTS UTF8 ON");
               ftpClient.execPBSZ(0);
               ftpClient.execPROT("P");
         else{
             throw new Exception("connection failed.....");}
         ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
        InputStream is= new FileInputStream("C:\\movie.avi");
         ftpClient.setUseEPSVwithIPv4(true);
             ftpClient.storeFile(remotePath, is);
         is.close();
       }
         catch (SocketException e) {
    e.printStackTrace();
        } catch (IOException e) {
    e.printStackTrace();
        }

无法上传大于 19Mb 的文件。 storeFile 方法抛出 IOException 且 StackTrace 为空。您可以看到下面的IOException变量:

   e    CopyStreamException  (id=39)    
    cause   CopyStreamException  (id=39)    
    detailMessage   "IOException caught while copying." (id=45) 
    ioException SocketException  (id=46)    
        cause   SocketException  (id=46)    
        detailMessage   "Connection reset by peer: socket write error" (id=50)  
        stackTrace  null    
    stackTrace  null    
    totalBytesTransferred   19084288    

实际上它的行为方式如下:

1)当我开始上传时,创建了零大小的文件,而我上传文件大小仍然为零并且发生异常时,这个空文件被 FTP 删除。

2)有趣的是,FileZila 也无法上传这些文件,但其大小限制为 70Mb。

我错过了什么吗?

I'm trying to upload large file (>100Mb) using Apache commons-net FTP library to Secure FTP Server IIS.

Here is my code:

try{
ftpClient = new FTPSClient("TLS", false);
        this.ftpClient.setDataTimeout(6000000);
        this.ftpClient.setConnectTimeout(6000000);
        ftpClient.connect(host, port);
        ftpClient.login(userName, password);
            ftpClient.enterLocalPassiveMode();
         if (ftpClient.getReplyCode() == 230){
               ftpClient.sendCommand("OPTS UTF8 ON");
               ftpClient.execPBSZ(0);
               ftpClient.execPROT("P");
         else{
             throw new Exception("connection failed.....");}
         ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
        InputStream is= new FileInputStream("C:\\movie.avi");
         ftpClient.setUseEPSVwithIPv4(true);
             ftpClient.storeFile(remotePath, is);
         is.close();
       }
         catch (SocketException e) {
    e.printStackTrace();
        } catch (IOException e) {
    e.printStackTrace();
        }

It fails to upload files larger then 19Mb. storeFile methods throws IOException with empty StackTrace. You can see below IOException variables:

   e    CopyStreamException  (id=39)    
    cause   CopyStreamException  (id=39)    
    detailMessage   "IOException caught while copying." (id=45) 
    ioException SocketException  (id=46)    
        cause   SocketException  (id=46)    
        detailMessage   "Connection reset by peer: socket write error" (id=50)  
        stackTrace  null    
    stackTrace  null    
    totalBytesTransferred   19084288    

Actually it behaves the following way:

1) when I'm starting upload, zero size file created, while I'm uploading file size is still zero and when the exception occurs, this empty file removed by FTP.

2) funny thing is that FileZila fails to upload these files as well, but its limit size is 70Mb.

Am I missing something?

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

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

发布评论

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

评论(1

通知家属抬走 2024-12-29 19:11:54

出色地。令人遗憾的是,这个问题是由防火墙引起的,它在 5 分钟超时后关闭了数据端口。

Well. Sad by true, the problem caused by firewall, which closed Data port after 5 minutes time out.

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