I download a file using ftp4j library, its size is 0 byte. I get no exception. So I use jstack pid ,here is the snippet about 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)`
It seems that sun.nio.cs.StreamDecoder.read
is locked for some reason. But I can not figure out it. Wireshark
show the last communication.
DATA SENDING IS OVER! FOR IF I CLOSE THE APPLICATION, THE FILE WILL BE THE SAME AS THAT ON THE SERVER THAN 0 BYTE.
I searched here, but seems cannot find the one fit my issue. PLS tell the reason and solution.
Here is my code.
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" );
}
}
}
It works when I don't encapsulate with org.quartz.Job. But I need schedule this ftp job
.
I change some codes ,but not work, the funny way of working remains.