ftp4j下载文件,大小为0字节

时间:2018-08-23 17:42:00

标签: java ftp4j

我使用ftp4j库下载文件,其大小为0字节。我也不例外。因此,我使用jstack pid,这是有关ftp的代码段。

`"Thread-17" #63 prio=5 os_prio=0 tid=0x0000000021154000 nid=0x2bf0 runnable 
[0x00000000275ae000]
   java.lang.Thread.State: RUNNABLE
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
    at java.net.SocketInputStream.read(SocketInputStream.java:170)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
    - locked <0x000000076e90ca80> (a java.io.InputStreamReader)
    at sun.nio.cs.StreamDecoder.read0(StreamDecoder.java:127)
    - locked <0x000000076e90ca80> (a java.io.InputStreamReader)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:112)
    at java.io.InputStreamReader.read(InputStreamReader.java:168)
    at it.sauronsoftware.ftp4j.NVTASCIIReader.readLine(NVTASCIIReader.java:105)
    at it.sauronsoftware.ftp4j.FTPCommunicationChannel.read(FTPCommunicationChannel.java:142)
    at it.sauronsoftware.ftp4j.FTPCommunicationChannel.readFTPReply(FTPCommunicationChannel.java:187)
    at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3390)
    - locked <0x000000076e074080> (a java.lang.Object)
    at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3193)
    at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3098)
    at com.ron.newgen.ftp.FtpDownloadClienter.download(FtpDownloadClienter.java:60)
    at com.ron.newgen.ftp.FtpThread.run(FtpThread.java:56)
    - locked <0x000000076e881c28> (a com.ron.newgen.ftp.FtpThread)
    at java.lang.Thread.run(Thread.java:745)`

似乎sun.nio.cs.StreamDecoder.read由于某种原因被锁定。但是我不知道。 Wireshark显示上一次通讯。

enter image description here

数据发送已结束!如果我关闭该应用程序,则该文件将与服务器上的字节数相同,为0个字节以上。

我在这里搜索,但似乎找不到适合我的问题的那个。请使用PLS告知原因和解决方法。

这是我的代码。

  public class FtpJob implements org.quartz.Job 

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
          FtpDownload ftpdownload = new FtpDownload(ftp, -1);
          ftpdownload.download();
  }


  public class FtpDownload(){

        ......

        private FtpDownloadClienter ftp;


        public void download() {

              try {
                    ftp.openConnection();

                    String home = "/home/";
                    String d1 = "";
                    d1 = prefix;
                    String remoteFileName = d1 + ".tar.gz";
                    for(String p:province){
                          log.debug(p);
                          if(!p.equals("jiangsu")){
                                continue;
                          }
                          String remoteFolderPath = home + p +"/" +  d1 + "/";
                          log.info(remoteFolderPath);
                          String clientpath = "f:\\ftp\\";
                          log.info(clientpath);
                          File file = new File(clientpath);
                          if(!file.isDirectory()){
                                file.mkdirs();
                          }

                          ftp.download(remoteFolderPath, remoteFileName, clientpath);
                     }

               } catch (Exception e) {
                     log.debug(e.getMessage(), e);
               }finally{
                     ftp.closeConnection();
               }
      }
  }


  public class FtpDownloadClienter{
        private FTPClient client = new FTPClient();

        public  void openConnection()throws Exception{
              client.connect(ftpHost, ftpPort);
              client.login(ftpUser, ftpPasswd);

        }

           public  void download(String remoteFolderPath, String remoteFileName, String localFolderPath) {



                 try {
                       client.changeDirectory(remoteFolderPath);
                       client.setPassive(true);
                       client.download(remoteFileName, new File(localFolderPath + remoteFileName), new MyTransferListener());
                 } catch (FTPException e) {
                             e.printStackTrace();
                             if(e.getCode() == 550){
                                   System.out.println("File not found : " + remoteFileName  );
                             }
                } catch (Exception e) {
                      e.printStackTrace();
                } finally{
                      log.info("Downloaded" );
                }
            }


  }

当我不使用org.quartz.Job封装时,它可以工作。但是我需要安排这个ftp job

我更改了一些代码,但没有用,有趣的工作方式仍然存在。

0 个答案:

没有答案