0

我使用 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显示最后一次通信。

在此处输入图像描述

数据发送结束!因为如果我关闭应用程序,文件将与服务器上的文件相同,超过 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

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

4

0 回答 0