Hello,
I use the following Java code under Windows to move files to download from my website using FTP protocol. The code works under windows fine. Android on the device I get an IOException (unable to connect to server unable to retrieve file 550).
Do I have SU privileges to a web space medium can access FTP? How do I do that?
I use the following Java code under Windows to move files to download from my website using FTP protocol. The code works under windows fine. Android on the device I get an IOException (unable to connect to server unable to retrieve file 550).
Do I have SU privileges to a web space medium can access FTP? How do I do that?
B4X:
private boolean loadStreamPerFTP(String ftpServer, int port, String ftpPath, String user, String pwd, String fileName, File destination, String ftpMode) throws MalformedURLException, IOException {
boolean result = false;
if (ftpServer != null && fileName != null && destination != null) {
StringBuffer sb = new StringBuffer("ftp://");
if (user != null && pwd != null) {
sb.append(user);
sb.append(':');
sb.append(pwd);
sb.append('@');
}
sb.append(ftpServer);
sb.append(":" + Integer.toString(port));
if (ftpPath.endsWith("/") == false) {
ftpPath = ftpPath + "/";
}
sb.append(ftpPath + fileName);
String mode = null;
if (ftpMode.length() == 0 || ftpMode == null) {
mode = "i";
} else {
mode = ftpMode;
}
sb.append(";type=" + mode);
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
URL url = new URL(sb.toString());
URLConnection urlCON = url.openConnection();
bis = new BufferedInputStream(urlCON.getInputStream());
bos = new BufferedOutputStream(new FileOutputStream(destination.getName()));
int i;
while ((i = bis.read()) != -1) {
bos.write(i);
}
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException ioe) {
// ErrorMessage("(Method: loadStreamPerFTP");
ioe.printStackTrace();
result = false;
}
if (bos != null) {
try {
bos.close();
result = true;
} catch (IOException ioe) {
// ErrorMessage("(Method: loadStreamPerFTP");
ioe.printStackTrace();
result = false;
}
}
} else {
// ErrorMessage("(Method: loadStreamPerFTP (Server not Found!)");
result = false;
}
}
} else {
result = false;
}
return result;
}