私は、commons net FTP 3.5とJava 1.8.0.45を使用してFTP経由でファイルの名前を変更しようとしています。 170Kの小さなファイル(25GB)を含む特定のフォルダが1つあります。このフォルダを一覧表示しようとするたびに、例外の下に戻ります。残りのフォルダについては、正常に実行され、ファイルの名前が変更されます。FTP経由の170Kファイルを含むフォルダに対してFTPConnectionClosedExceptionがスローされるのはなぜですか?
org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:316)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:292)
at org.apache.commons.net.ftp.FTP.getReply(FTP.java:712)
at org.apache.commons.net.ftp.FTPClient.completePendingCommand(FTPClient.java:1857)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3420)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3335)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:3012)
at TestFTP.execute(TestFTP.java:27)
at TestFTP.main(TestFTP.java:12)
org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:316)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:292)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:503)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:628)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:602)
at org.apache.commons.net.ftp.FTP.quit(FTP.java:884)
at org.apache.commons.net.ftp.FTPClient.logout(FTPClient.java:1152)
at TestFTP.execute(TestFTP.java:62)
at TestFTP.main(TestFTP.java:12)
コード:
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
public class TestFTP {
public static void main(String[] args) {
TestFTP.execute(args[0], args[1]);
}
static DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static void execute(String ip, String folder) {
String server = ip;
int port = 21;
String user = "adminuser";
String pass = "adminuser";
long start = System.currentTimeMillis();
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(server, port);
ftpClient.login(user, pass);
FTPFile[] files = ftpClient.listFiles(folder);
for (FTPFile file : files) {
String details = file.getName();
// renaming file
String oldFile = folder + file.getName();
String newFile = folder + "_X_" + file.getName();
boolean success = ftpClient.rename(oldFile, newFile);
if (success) {
System.out.println(oldFile + " was successfully renamed to: "
+ newFile);
} else {
System.out.println("Failed to rename: " + oldFile);
}
}
ftpClient.logout();
ftpClient.disconnect();
long end = System.currentTimeMillis();
System.out.println("time:" +(end-start));
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (ftpClient.isConnected()) {
try {
ftpClient.logout();
ftpClient.disconnect();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
}
タイムアウトを増やすなどのような大規模なフォルダを一覧表示するための要求に応えるために、私のFTPサーバーを作成する方法はありますか?または私は何かが恋しいですか?前もって感謝します !
を、あなたは、ファイルのリストを行うために取っているどのくらいの時間を持っているとアイデアのですか? –
電話を持ちます。 FTPを使用して170,000ファイルの名前を変更する理由は何ですか?これをサーバーで直接行うのは、さらに効率的です。そして、私はJavaコードではなく、バッチファイルまたはシェルスクリプトを使用します。 – EJP
@DanielHernándezこのフォルダでは、リストは決して成功しませんでした。約100のファイルを持つ他のフォルダについては、約500ミリ秒かかる。 – bkrish