[下面是我将HTML文件写到FTP到服务器的一段代码。尽管代码中没有错误,但是在执行程序时,FTPClient上出现了No Class Def Found Error。我已经下载了commons-net-3.6-bin并将以下jar文件导入到我的项目库中commons-net-3.6.jarcommons-net-3.6-source.jarcommons-net-examples-3.6.jar
不确定从这里要去哪里。
String projectPath = System.getProperty("user.dir");
String ImportSKU = projectPath + "Import SKU.HTML";
File file = new File(ImportSKU);
FTPClient client = new FTPClient();
String filename = ImportSKU;
// Read the file from resources folder.
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try (InputStream is = classLoader.getResourceAsStream(filename)) {
client.connect("ftp://www.data.com");
client.login("usedid", "password");
// Store file to server
client.storeFile(filename, is);
client.logout();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
我有同样的问题
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
public class main {
public static void main(String[] args) {
String server = "serverip";
int port = 21;
String user = "user";
String pass = "pass";
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(server, port);
ftpClient.login(user, pass);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
String remoteFile1 = "filename.csv";
File downloadFile1 = new File("C:/filename.csv");
OutputStream outputStream1 = new BufferedOutputStream(new
FileOutputStream(downloadFile1));
boolean success = ftpClient.retrieveFile(remoteFile1, outputStream1);
outputStream1.close();
if (success) {
System.out.println("File #1 has been downloaded successfully.");
}
} catch (IOException ex) {
System.out.println("Error: " + ex.getMessage());
ex.printStackTrace();
} finally {
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (IOException ex) {
System.out.println("ex end");
ex.printStackTrace();
}
}
}
我也在FTPClient上也收到“找不到类定义错误”。您是否找到了解决方案?