Testing out a few server side things with Java. I need to be able to upload data to the ftp server. I’ve already searched the internet and found some code to use:
FTPClient ftpclient = new FTPClient();
FileInputStream fis = null;
boolean result;
String ftpServerAddress = "0002uh4.wcomhost.com";
String userName = "jacobpickens";
String password = "passwordthatiwonttellyou";
try {
ftpclient.connect(ftpServerAddress);
result = ftpclient.login(userName, password);
if (result == true) {
System.out.println("Logged in Successfully !");
} else {
System.out.println("Login Fail!");
return;
}
ftpclient.setFileType(FTP.BINARY_FILE_TYPE);
ftpclient.changeWorkingDirectory("/");
File file = new File("test.txt");
String testName = file.getName();
fis = new FileInputStream(file);
// Upload file to the ftp server
result = ftpclient.storeFile(testName, fis);
if (result == true) {
System.out.println("File is uploaded successfully");
} else {
System.out.println("File uploading failed");
}
ftpclient.logout();
} catch (FTPConnectionClosedException e) {
e.printStackTrace();
} finally {
try {
ftpclient.disconnect();
} catch (FTPConnectionClosedException e) {
System.out.println(e);
}
}
I’m using Apache Commons Net 3.3 and the code runs fine. No errors. Even says it completed the file transfer. But when I check my files online and in my FTP client there is no file to be found. Any ideas? (FYI: I’m using Web.com as my server host)