我正在尝试使用FTPServer Apache构建嵌入java的FTP服务器/客户端。 登录到服务器后,我需要在服务器上创建一个目录,以便开始上传(或者这就是我理解我至少应该做的事情)。到目前为止,服务器端运行良好。 但它似乎没有用。你能看到我忽略的东西吗? 谢谢
客户的代码:
package client;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPConnectionClosedException;
class ftp{
public static void main(String[] args) throws IOException {
FTPClient client = new FTPClient();
FileInputStream fis = null;
boolean result;
String ftpServerAddress="192.168.171.133";
String userName="iman";
String password="iman";
try {
client.connect(ftpServerAddress, 1959);
result = client.login(userName, password);
if (result == true) {
System.out.println("Successfully logged in!");
} else {
System.out.println("Login Fail!");
return;
}
//Changing the working directory
result=client.makeDirectory("/home/Serveur/workspac");
if(result==true){
System.out.println("New Directory is created on Ftp Server!");
}
else{
System.out.println("Unable to create new directory!");
}
client.setFileType(FTP.BINARY_FILE_TYPE);
File file = new File("/home/client/workspace/Client/dos");
String testName = file.getName();
fis = new FileInputStream(file);
int c= client.getReplyCode();
System.out.println(c);
// Upload file to the ftp server
result = client.storeFile(testName, fis);
//result= client.remoteStore(testName);
if (result == true) {
System.out.println("File is uploaded successfully");
} else {
System.out.println("File uploading failed");
}
client.logout();
} catch (FTPConnectionClosedException e) {
e.printStackTrace();
} finally {
try {
client.disconnect();
} catch (FTPConnectionClosedException e) {
System.out.println(e);
}
}
}
}
输出如下:
Successfully logged in!
Unable to create new directory!
200
File uploading failed