我想使用 FTP 在服务器上上传一个 .class 文件(ABC.class)。
试过:1>
public boolean uploadFileOnFTPServer(File file, String uploadToPath) {
boolean isUploaded = false;
try {
FileInputStream bis = new FileInputStream(file);
if (connectToFTPServer()) {
if (ftpClient.login(userName, password)) {
System.out.println("Logged in to server. Username: " + userName);
if (ftpClient.changeWorkingDirectory(uploadToPath)) {
System.out.println("Navigated to path " + uploadToPath);
if (ftpClient.storeFile(file.getName(), bis)) {
bis.close();
System.out.println("File " + file.getName() + " uploaded to server.");
isUploaded = true;
}
}
} catch (Exception e) {
strRemarks = "Exception reported: Unable to upload file. Error Details: " + e.toString();
System.out.println(strRemarks);
e.printStackTrace();
} finally {
disconnectFTPServer();
}
return isUploaded;
}
也试过:
2>
InputStream bis = new FileInputStream(file);
3>
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
该文件正在上传到服务器上,但其已损坏或内容未正确存储在文件中。
任何人都可以请帮助。