Proftpd - 上传后的0kb文件

时间:2015-01-05 13:22:35

标签: java ftp

我已经搜索了很长时间但无法找到解决方案。 我试图将文件从我的计算机上传到我的ftp服务器。但每次我尝试,我只创建一个0kb的文件。

我已经尝试了

  1. 关闭防火墙
  2. 文件夹
  3. 上的chmod -R 775
  4. 20个不同版本的客户端
  5. 被动转移模式
  6. 二进制文件类型
  7. 二进制类型传输模式
  8. 使用最新的commons-net libary(3.3)
  9. 相关:

    0 kb file created once FTP is done in java

    FTP a file to server, but it the result arrives with zero byte size

    public static void goforIt(){
        FTPClient ftpClient = new FTPClient();
        ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
        try {
    
            ftpClient.connect("xxx.xxx.xxx.xx");
    
            ftpClient.login("xx", "xx");
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            //ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
            ftpClient.enterLocalPassiveMode();
            boolean w = ftpClient.changeWorkingDirectory("/var/www/xx");
    
    
            if (ftpClient.getReplyString().contains("250")) {
                InputStream in = null;
                try{
                    in = new FileInputStream(new File("xx.mp4"));
                }catch (Exception e){
                    e.printStackTrace();
                    return;
                }
    
                ftpClient.sendCommand("PWD");
    
    
                boolean result = ftpClient.storeFile("/var/www/public_videos/xx.mp4", in);
                System.out.println(ftpClient.getReplyString() + result);
    
                in.close();
                ftpClient.logout();
                ftpClient.disconnect();
            }
    
        } catch (SocketException e) {
            e.printStackTrace();
        } catch (UnknownHostException e) {
             e.printStackTrace();
        } catch (IOException e) {
             e.printStackTrace();
        }
    }
    

    日志:

    220 ProFTPD 1.3.4a Server (Debian) [::ffff:xx.xxx.xx.xx]
    USER xx
    331 Password required for xx
    PASS xx
    230 User xx logged in
    TYPE I
    200 Type set to I
    CWD /var/www/xx
    250 CWD command successful
    PWD
    257 "/var/www/xx" is the current directory
    PASV
    227 Entering Passive Mode (xx,xx,xx,xxx,xxx,xx).
    STOR /var/www/public_videos/xx.mp4
    150 Opening BINARY mode data connection for /var/www/xx/xx.mp4
    226 Transfer complete
    226 Transfer complete
    true
    QUIT
    221 Goodbye.
    

    结果:

    http://puu.sh/e6pVx/051c175f9e.png

1 个答案:

答案 0 :(得分:0)

卸下

ftpClient.enterLocalPassiveMode();

导致解决我的问题