When I try to upload a simple text file with the apache commons ftpClient and this code:
imports*
public class ftpUpload {
public static void main(String[] args) {
FTPClient ftp = new FTPClient();
int reply;
// connect
try {
ftp.connect(serverAdd);
ftp.login(username,password);
reply = ftp.getReplyCode();
if(FTPReply.isPositiveCompletion(reply)){
System.out.println("Connected Success..");
// upload file
try {
String fileDir = "testfile.txt";
FileInputStream in = null;
in = new FileInputStream(fileDir);
ftp.storeFile(fileDir,in);
System.out.println("File upload complete..");
}catch(IOException e){
System.out.println(e);
}
ftp.disconnect();
System.out.println("Disconnected..");
}else {
System.out.println("Connection Failed..");
ftp.disconnect();
}
} catch (SocketException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
A file gets created in the root of the FTP server but it is empty. what´s wrong? I already tried to change the ftp mode to BINARY when uploading a PDF file. but the file is also 0 in size.
ftp.setFileType(FTP.BINARY_FILE_TYPE);
I also only want to upload a bunch of txt files, so the default ascii mode should be fine, right?