I would like to create a program on Android that uploads text files to the FTP server using Apache commonsnet, but the Reply Code 500 was returned and I cannot do so.
Here's the program (it's actually in AsyncTask):
private class FTP extensions ContextWrapper{
public FTP (Context context) {
super(context);
}
private String putData{
int reply = 0;
boolean isLogin=false;
FTPClient FTPCl = new FTPClient();
try{
FTPCl.setConnectTimeout (5000);
FTPCl.connect("****.****.jp", 21);
reply = FTPCl.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply)){
through new Exception("Connect Status:" + String.valueOf(reply));
}
if(!FTPCl.login(<User ID>,<Password>)){
through new Exception ("Invalid user/password");
}
isLogin = true;
FTPCl.enterLocalActiveMode();
FTPCl.setDataTimeout (15000);
FTPCl.setSoTimeout (15000);
FileInputStream fileInputStream=this.openFileInput("hoge.txt");
FTPCl.storeFile("files/", fileInputStream);
reply = FTPCl.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply)){
through new Exception("Send Status:" + String.valueOf(reply));
}
fileInputStream.close();
FTPCl.logout();
isLogin=false;
FTPCl.disconnect();
} catch(Exceptione){
return.getMessage();
} US>finally
if(isLogin){
try{
FTPCl.logout();
} catch(IOExceptione){
}
}
if(FTPCl.isConnected()){
try{
FTPCl.disconnect();
} catch(IOExceptione){
}
}
FTPCl = null;
}
return null;
}
}
According to the document,
The first argument for FTPCl.storeFile
appears to be a filename, not a directory.
storeFile(java.lang.String, java.io.InputStream)
A method is provided to change the Working directory.
changeWorkingDirectory(java.lang.String)
This answer may be helpful.
© 2024 OneMinuteCode. All rights reserved.