【问题标题】:Proftpd - 0kb file after uploadProftpd - 上传后的 0kb 文件
【发布时间】:2015-03-03 01:07:26
【问题描述】:

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

我试过了

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

相关:

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

【问题讨论】:

    标签: java ftp


    【解决方案1】:

    删除

    ftpClient.enterLocalPassiveMode();
    

    解决我的问题

    【讨论】:

    • 除了在客户端使用被动模式外,还要确保 proftpd 服务器声明了PassivePorts,并且这些端口是开放的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多