Java Question Java code does not work on Android device

Amalkotey

Active Member
Licensed User
Longtime User
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?

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;
}
 

Cynikal

Member
Licensed User
Longtime User
You said: "Do I have SU privileges to a web space medium can access FTP? How do I do that?"



What do you mean by that?

Because, it looks like you're asking if you have SU privileges...
 

Amalkotey

Active Member
Licensed User
Longtime User
@Erel:
As I am writing a lib B4A for our project, I need the functionality in my Lib I 'm going to write to Alain Bailleul and ask him how he did it.

@Cynikal:
It looks so aius that the request is blocked by AndroidOS. The code works correctly under Eclipse and Android, B4A involved in, I get no access to the webspace using FTP protocol.

regards
Amalkotey
 
Top