I want my App to list all directories and files on my FTP-Server. This is the code from How to list ftp directories with android?:
FTPFile[] files = null;
files = ftpClient.listDirectories();
String path = null;
for (int i = 0; i < files.length; i++) {
path = files[0].getName();
Log.d("CONNECT", "Directories: "+ files[i].getName());
}
FTPFile[] files2 = ftpClient.listFiles(topPath);
for (int j = 0; j < files2.length; j++) {
Log.d("CONNECT", "Below " + files[j].getName()
+ " is " + files2[j].getName());
}
}
Now this works for only for the first two layers. How can I manage to get as deep as necessary so I can list files that in folders that are in folders that are in folders and so on?
Thanks in advance :)
Now what I tried (not quite) recursively:
{ ...
FTPFile[] files = ftpClient.listFiles();
listContent(files);
.... }
private void listContent(FTPFile[] file) throws IOException {
FTPFile[] list = ftpClient.listDirectories();
if (list != null) {
for (FTPFile f : list) {
if (f.isDirectory()) {
Log.d(TAG, "directory: " + f.getName());
} else {
Log.d(TAG, "file: " + f.getName());
}
}
listContent(list);
} else return;
}
This code lets me get just the first layer of directories, the FTPFile[] is overwritten in ever new cycle.
How can I do that?
UPDATE:
Here's my solution. This code walks the whole content of the host-adress. Thanks to all who helped me:
private void listContent(String s) throws IOException {
try {
FTPFile[] ftpFiles = ftpClient.listFiles(s);
int length = ftpFiles.length;
for (int i = 0; i < length; i++) {
String name = ftpFiles[i].getName();
boolean isFile = ftpFiles[i].isFile();
if (isFile) {
Log.i(TAG, "File : " + name);
}
} else {
Log.i(TAG, "Directory : " + name);
if (ftpChangeDirectory(name) == true) {
Log.d("ftpChangeDirectory", name);
String newDir = ftpGetCurrentWorkingDirectory();
Log.d(TAG, "new Dir: " + newDir);
listContent(newDir);
}
}
}
ftpChangeDirectory("..");
String test = ftpGetCurrentWorkingDirectory();
Log.d("dirUp", test);
} catch (Exception e) {
e.printStackTrace();
}
}
I can't test it but something like this should work :
private void listAllFiles(String path) // path is the top folder to start the search
{
FTPFile[] files = ftpClient.listFiles(path); // Search all the files in the current directory
for (int j = 0; j < files.length; j++) {
Log.d("CONNECT", "Files: " + files[j].getName()); // Print the name of each files
}
FTPFile[] directories = ftpClient.listDirectories(path); // Search all the directories in the current directory
for (int i = 0; i < directories.length; i++) {
String dirPath = directories[i].getName();
Log.d("CONNECT", "Directories: "+ dirPath); // Print the path of a sub-directory
listAllFiles(dirPath); // Call recursively the method to display the files in the sub-directory
}
}
Anyway, i strongly recommend that you understand the code and check this link to learn more about recursivity.
Related
I've been bringing up the list of files in the folder as below, but I can't use the method below in Android Q(Android 10) or higher.
How do I load a list of files in the MUSIC folder using MediaStore?
public void getFileListInFolder() {
String path = Environment.getExternalStoragePublicDirectory(DIRECTORY_MUSIC);
File directory = null;
try {
directory = new File(path);
Log.i("debug","dir = " + directory);
}
catch (Exception e)
{
Log.i("debug","Uri e = " + e);
}
File[] files = directory.listFiles(new FileFilter() {
#Override
public boolean accept(File pathname) {
return pathname.isFile();
}
});
if(files != null)
{
for (int i = 0; i < files.length; i++) {
Log.i("debug", "FileName:" + files[i].getName());
}
}
}
getExternalStoragePublicDirectory is deprecated since Android Q
To improve user privacy, direct access to shared/external
storage devices is deprecated. When an app targets
{#link android.os.Build.VERSION_CODES#Q}, the path returned
from this method is no longer directly accessible to apps.
Apps can continue to access content stored on shared/external
storage by migrating to alternatives such as
{#link Context#getExternalFilesDir(String)},
{#link MediaStore}, or {#link Intent#ACTION_OPEN_DOCUMENT}.
That means could not read/write file of /storage/emulated/0/Music directly,
but could read/write file under /storage/emulated/0/Android/data/com.youapp/files/Music
public void getFileListInFolder() {
String path = getExternalFilesDir(DIRECTORY_MUSIC).getAbsolutePath();
Log.d(TAG, "getFileListInFolder:path " + path);
File directory = null;
try {
directory = new File(path);
Log.i(TAG,"dir = " + directory);
}
catch (Exception e)
{
Log.i(TAG,"Uri e = " + e);
}
File[] files = directory.listFiles();
Log.i(TAG, "getFileListInFolder:files " + files);
for (File f:
files) {
Log.d(TAG, "getFileListInFolder: " + f.getName());
}
if(files != null)
{
for (int i = 0; i < files.length; i++) {
Log.i(TAG, "FileName:" + files[i].getName());
}
}
}
I am able to fetch all the images from any specified non hidden folder from device but how can I get all the images from a hidden specified folder.
As soon as I mention my hidden folder name in the query, cursor return null
public static List<MediaData> getAppScannedImages(Context context) {
Cursor imagecursor = null;
List<MediaData> gallerydata = new ArrayList<MediaData>();
try {
final String orderBy = Images.ImageColumns.DATE_TAKEN + " DESC";
imagecursor = context.getContentResolver()
.query(Images.Media.EXTERNAL_CONTENT_URI,
projectionImage,
Images.Media.BUCKET_DISPLAY_NAME + "='"
+ ".myHiddenFolder" + "'", null,
orderBy);
if (imagecursor != null) {
imagecursor.moveToFirst();
int count = imagecursor.getCount();
for (int i = 0; i < count; i++) {
MediaData galData = new MediaData();
galData.setKey_id(i);
galData.setId(imagecursor.getString(0));
galData.setName(imagecursor.getString(1));
galData.setPath(imagecursor.getString(2));
galData.setDate(imagecursor.getString(3));
gallerydata.add(galData);
imagecursor.moveToNext();
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (imagecursor != null) {
imagecursor.close();
}
}
return gallerydata;
}
You can try a different approach.
You have to find out the list of hidden folder from sd card and search all those folders for images.
the follwoing code is displays hidden files:
public void goTODir(File dir) {
//dir is initail dir like="/mnt/sdcard"
String imageType = ".jpg";
File[] listFile = dir.listFiles();
if (listFile != null) {
for (int i = 0; i < listFile.length; i++) {
if (listFile[i].isDirectory()) {
goTODir(listFile[i]);
} else {
if (listFile[i].isHidden()){
if(listFile[i].getName().endsWith(imageType))
{
//add to your array list
}
}
}
}
}
}
String path = Environment.getExternalStorageDirectory().toString();
File dir = new File(path);
File listFile[] = dir.listFiles();
for (int i = 0; i < listFile.length; i++) {
if(listFile[i].getAbsolutePath().contains("your hidden folder name")){
File dirtest = new File(listFile[i].getAbsolutePath());
File listFiletest[] = dirtest.listFiles();
for (int j = 0; j < listFiletest.length; j++) {
get all images from hidden folder
}
}
}
For Kotlin Lover
companion object {
const val FOLDER_PATH = "/YourFolder/.hideen/"
}
/**
* Method to get all Image Path
* #return [ArrayList]
* */
fun getImagePath(): ArrayList<String> {
// image path list
val list: ArrayList<String> = ArrayList()
// fetching file path from storage
val file = File(Environment.getExternalStorageDirectory().toString() + FOLDER_PATH)
val listFile = file.listFiles()
if (listFile != null && listFile.isNullOrEmpty()) {
Arrays.sort(listFile, LastModifiedFileComparator.LASTMODIFIED_REVERSE)
}
if (listFile != null) {
for (imgFile in listFile) {
if (
imgFile.name.endsWith(".jpg")
|| imgFile.name.endsWith(".jpeg")
|| imgFile.name.endsWith(".png")
) {
val model : String = imgFile.absolutePath
list.add(model)
}
}
}
// return imgPath List
return list
}
I am trying to check whether device having external storage or not by using external storage path like this given below
if (new File("/ext_card/").exists()) {
specialPath = "/ext_card/";
} else if (new File("/mnt/sdcard/external_sd/").exists()) {
specialPath = "/mnt/sdcard/external_sd/";
} else if (new File("/storage/extSdCard/").exists()) {
specialPath = "/storage/extSdCard/";
} else if (new File("/mnt/extSdCard/").exists()) {
specialPath = "/mnt/extSdCard/";
} else if (new File("/mnt/sdcard/external_sd/").exists()) {
specialPath = "/mnt/sdcard/external_sd/";
} else if (new File("storage/sdcard1/").exists()) {
specialPath = "storage/sdcard1/";
}
But in marshmallow I con't find this path and while checking using ES FILEMANAGER, they give like storage/3263-3131 in Moto G 3rd generation. While check in other marshmallow devices that numbers getting differ. Please help me to check that marshmallow device have external storage or not? and if storage found means how to get the path of that external storage?
Note:- I gave permission for storage in my application and also enabled storage permission in settings for my app.
Thanks in advance and did you find any mistake in my question please crt it. thank you again.
Here's my solution, which is guaranteed to work till Android 7.0 Nougat:
/* returns external storage paths (directory of external memory card) as array of Strings */
public String[] getExternalStorageDirectories() {
List<String> results = new ArrayList<>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //Method 1 for KitKat & above
File[] externalDirs = getExternalFilesDirs(null);
String internalRoot = Environment.getExternalStorageDirectory().getAbsolutePath().toLowerCase();
for (File file : externalDirs) {
if(file==null) //solved NPE on some Lollipop devices
continue;
String path = file.getPath().split("/Android")[0];
if(path.toLowerCase().startsWith(internalRoot))
continue;
boolean addPath = false;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
addPath = Environment.isExternalStorageRemovable(file);
}
else{
addPath = Environment.MEDIA_MOUNTED.equals(EnvironmentCompat.getStorageState(file));
}
if(addPath){
results.add(path);
}
}
}
if(results.isEmpty()) { //Method 2 for all versions
// better variation of: http://stackoverflow.com/a/40123073/5002496
String output = "";
try {
final Process process = new ProcessBuilder().command("mount | grep /dev/block/vold")
.redirectErrorStream(true).start();
process.waitFor();
final InputStream is = process.getInputStream();
final byte[] buffer = new byte[1024];
while (is.read(buffer) != -1) {
output = output + new String(buffer);
}
is.close();
} catch (final Exception e) {
e.printStackTrace();
}
if(!output.trim().isEmpty()) {
String devicePoints[] = output.split("\n");
for(String voldPoint: devicePoints) {
results.add(voldPoint.split(" ")[2]);
}
}
}
//Below few lines is to remove paths which may not be external memory card, like OTG (feel free to comment them out)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
for (int i = 0; i < results.size(); i++) {
if (!results.get(i).toLowerCase().matches(".*[0-9a-f]{4}[-][0-9a-f]{4}")) {
Log.d(LOG_TAG, results.get(i) + " might not be extSDcard");
results.remove(i--);
}
}
} else {
for (int i = 0; i < results.size(); i++) {
if (!results.get(i).toLowerCase().contains("ext") && !results.get(i).toLowerCase().contains("sdcard")) {
Log.d(LOG_TAG, results.get(i)+" might not be extSDcard");
results.remove(i--);
}
}
}
String[] storageDirectories = new String[results.size()];
for(int i=0; i<results.size(); ++i) storageDirectories[i] = results.get(i);
return storageDirectories;
}
I found the solution for this over here https://stackoverflow.com/a/13648873/842607
The code is -
public static HashSet<String> getExternalMounts() {
final HashSet<String> out = new HashSet<String>();
String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*";
String s = "";
try {
final Process process = new ProcessBuilder().command("mount")
.redirectErrorStream(true).start();
process.waitFor();
final InputStream is = process.getInputStream();
final byte[] buffer = new byte[1024];
while (is.read(buffer) != -1) {
s = s + new String(buffer);
}
is.close();
} catch (final Exception e) {
e.printStackTrace();
}
// parse output
final String[] lines = s.split("\n");
for (String line : lines) {
if (!line.toLowerCase(Locale.US).contains("asec")) {
if (line.matches(reg)) {
String[] parts = line.split(" ");
for (String part : parts) {
if (part.startsWith("/"))
if (!part.toLowerCase(Locale.US).contains("vold"))
out.add(part);
}
}
}
}
return out;
}
The other one is the hack which I found from the same page -
private static final Pattern DIR_SEPORATOR = Pattern.compile("/");
/**
* Raturns all available SD-Cards in the system (include emulated)
*
* Warning: Hack! Based on Android source code of version 4.3 (API 18)
* Because there is no standart way to get it.
* TODO: Test on future Android versions 4.4+
*
* #return paths to all available SD-Cards in the system (include emulated)
*/
public static String[] getStorageDirectories()
{
// Final set of paths
final Set<String> rv = new HashSet<String>();
// Primary physical SD-CARD (not emulated)
final String rawExternalStorage = System.getenv("EXTERNAL_STORAGE");
// All Secondary SD-CARDs (all exclude primary) separated by ":"
final String rawSecondaryStoragesStr = System.getenv("SECONDARY_STORAGE");
// Primary emulated SD-CARD
final String rawEmulatedStorageTarget = System.getenv("EMULATED_STORAGE_TARGET");
if(TextUtils.isEmpty(rawEmulatedStorageTarget))
{
// Device has physical external storage; use plain paths.
if(TextUtils.isEmpty(rawExternalStorage))
{
// EXTERNAL_STORAGE undefined; falling back to default.
rv.add("/storage/sdcard0");
}
else
{
rv.add(rawExternalStorage);
}
}
else
{
// Device has emulated storage; external storage paths should have
// userId burned into them.
final String rawUserId;
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
{
rawUserId = "";
}
else
{
final String path = Environment.getExternalStorageDirectory().getAbsolutePath();
final String[] folders = DIR_SEPORATOR.split(path);
final String lastFolder = folders[folders.length - 1];
boolean isDigit = false;
try
{
Integer.valueOf(lastFolder);
isDigit = true;
}
catch(NumberFormatException ignored)
{
}
rawUserId = isDigit ? lastFolder : "";
}
// /storage/emulated/0[1,2,...]
if(TextUtils.isEmpty(rawUserId))
{
rv.add(rawEmulatedStorageTarget);
}
else
{
rv.add(rawEmulatedStorageTarget + File.separator + rawUserId);
}
}
// Add all secondary storages
if(!TextUtils.isEmpty(rawSecondaryStoragesStr))
{
// All Secondary SD-CARDs splited into array
final String[] rawSecondaryStorages = rawSecondaryStoragesStr.split(File.pathSeparator);
Collections.addAll(rv, rawSecondaryStorages);
}
return rv.toArray(new String[rv.size()]);
}
This library solve my problem.
https://github.com/hendrawd/StorageUtil
What i did is:
private File directory;
String[] allPath;
allPath = StorageUtil.getStorageDirectories(this);
for (String path: allPath){
directory = new File(path);
Methods.update_Directory_Files(directory);
}
Methods.update_Directory_Files()
// Retrieving files from memory
public static void update_Directory_Files(File directory) {
//Get all file in storage
File[] fileList = directory.listFiles();
//check storage is empty or not
if(fileList != null && fileList.length > 0)
{
for (int i=0; i<fileList.length; i++)
{
boolean restricted_directory = false;
//check file is directory or other file
if(fileList[i].isDirectory())
{
for (String path : Constant.removePath){
if (path.equals(fileList[i].getPath())) {
restricted_directory = true;
break;
}
}
if (!restricted_directory)
update_Directory_Files(fileList[i]);
}
else
{
String name = fileList[i].getName().toLowerCase();
for (String ext : Constant.videoExtensions){
//Check the type of file
if(name.endsWith(ext))
{
//first getVideoDuration
String videoDuration = Methods.getVideoDuration(fileList[i]);
long playbackPosition;
long percentage = C.TIME_UNSET;
FilesInfo.fileState state;
/*First check video already played or not. If not then state is NEW
* else load playback position and calculate percentage of it and assign it*/
//check it if already exist or not if yes then start from there else start from start position
int existIndex = -1;
for (int j = 0; j < Constant.filesPlaybackHistory.size(); j++) {
String fListName = fileList[i].getName();
String fPlaybackHisName = Constant.filesPlaybackHistory.get(j).getFileName();
if (fListName.equals(fPlaybackHisName)) {
existIndex = j;
break;
}
}
try {
if (existIndex != -1) {
//if true that means file is not new
state = FilesInfo.fileState.NOT_NEW;
//set playbackPercentage not playbackPosition
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(fileList[i].getPath());
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
retriever.release();
int duration = Integer.parseInt(time);
playbackPosition = Constant.filesPlaybackHistory.get(existIndex).getPlaybackPosition();
if (duration > 0)
percentage = 1000L * playbackPosition / duration;
else
percentage = C.TIME_UNSET;
}
else
state = FilesInfo.fileState.NEW;
//playbackPosition have value in percentage
Constant.allMemoryVideoList.add(new FilesInfo(fileList[i],
directory,videoDuration, state, percentage));
//directory portion
currentDirectory = directory.getPath();
unique_directory = true;
for(int j=0; j<directoryList.size(); j++)
{
if((directoryList.get(j).toString()).equals(currentDirectory)){
unique_directory = false;
}
}
if(unique_directory){
directoryList.add(directory);
}
//When we found extension from videoExtension array we will break it.
break;
}catch (Exception e){
e.printStackTrace();
Constant.allMemoryVideoList.add(new FilesInfo(fileList[i],
directory,videoDuration, FilesInfo.fileState.NOT_NEW, C.TIME_UNSET));
}
}
}
}
}
}
Constant.directoryList = directoryList;
}
in this i have redmi note prime 2.and i have no memory card.so when i found path and File[] externalDirs = getExternalFilesDirs(null); give null second postion value of file[].
}
The file utils which i am using in my service class is not retrieving the files from its path,but when i am using the same in activity its performing as required.
so can anyone suggest me the correct answer for my question.
These are my programming lines which i have used.
public class MyService extends Service
{
IBinder mBinder;
private File root;
private ArrayList<File> fileList = new ArrayList<File>();
#Override
public void onCreate()
{
root = new File(Environment.getExternalStorageDirectory() + "/user/");
getfile(root);
for (int i = 0; i < fileList.size(); i++)
{
if (fileList.get(i).isDirectory()) {
File userPath = new File(fileList.get(i).getPath());
File[] uFiles = userPath.listFiles();
for (int k = 0; k < uFiles.length; k++) {
File f1 = new File(uFiles[k].toString());
String comFile = Environment.getExternalStorageDirectory() + "/Download/" + uFiles[k].getName();
// System.out.println(comFile);
// System.out.println(f1.getPath());
File f2 = new File(comFile);
try {
boolean compare1and2 = FileUtils.contentEquals(f1, f2);
// Toast.makeText(getApplicationContext(), "Are " + uFiles[k] + " and " + comFile + " the same? " + compare1and2, Toast.LENGTH_SHORT).show();
if (!compare1and2) {
File f4 = new File(Environment.getExternalStorageDirectory() + "/upload/" + uFiles[k].getName());
File f3 = new File(comFile);
FileUtils.copyFile(f3, f4);
f1.delete();
Toast.makeText(getApplicationContext(), "File uploaded" , Toast.LENGTH_SHORT).show();
System.out.println("file uploaded");
} else {
f1.delete();
}
} catch (IOException e) {
e.printStackTrace();
}
}
fileList.get(i).delete();
}
}
}
public ArrayList<File> getfile (File dir)
{
Log.e("logger", dir.toString());
File listFile[] = dir.listFiles();
if (listFile != null && listFile.length > 0) {
for (int i = 0; i < listFile.length; i++) {
if (listFile[i].isDirectory()) {
fileList.add(listFile[i]);
getfile(listFile[i]);
} else {
if (listFile[i].getName().endsWith(".png")
|| listFile[i].getName().endsWith(".jpg")
|| listFile[i].getName().endsWith(".jpeg")
|| listFile[i].getName().endsWith(".gif"))
{
fileList.add(listFile[i]);
}
}
}
}
return fileList;
}
public IBinder onBind(Intent intent)
{
Toast.makeText(getApplicationContext()," onbind", Toast.LENGTH_SHORT).show();
return mBinder;
}
}
Null Pointer Exception
This is a generic issue as the instance of the class is not initiated, you are getting this error.
when you are using third party library and you are not sure how it may behave with certain methods, you should always check if the given instance generated by that method is null or not, before taking any action on that reference variable as that method may have returned null
In your code put conditions like this
if(object != null){
// now you can call methods on this reference variable as it is not null
}else{
// forget it, the reference variable, does not hold address to any object, if you try anything with this, VM will complain with Null Pointer Exception
}
I would recommend you to check this variables as following
root, listFile[], uFiles, f1, f2, f3, f4,
pay attention as you may consider some directories have sub-directories but that not always the case, so you have to check that listFiles() is indeed returns the array of files otherwise you have to deal with more bugs in the code
[SOLVED] How can I get a list of my Files and Folders on my ftp Server?
I know how to connect and upload a file, but not how to get the directory list:
try {
FTPClient ftpClient = new FTPClient();
ftpClient.connect(InetAddress.getByName("176.28.25.46"));
ftpClient.login("******", "******");
System.out.println("status :: " + ftpClient.getStatus());
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
// Prepare file to be uploaded to FTP Server
File file = new File("default.prop");
FileInputStream ifile = new FileInputStream(file);
// Upload file to FTP Server
ftpClient.storeFile("/subdomains/giveyourapps/httpdocs/apps/default.prop",ifile);
ftpClient.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
But every code snipped that I found on google didn't work for me :-/
try {
FTPClient ftpClient = new FTPClient();
ftpClient.connect(InetAddress.getByName("176.28.25.46"));
ftpClient.login("******", "******");
System.out.println("status :: " + ftpClient.getStatus());
String toppath = new String();
FTPFile[] ftpDirs = ftpClient.listDirectories();
for (int i = 0; i < ftpDirs.length; i++) {
toppath = ftpDirs[0].getName();
Log.d("CONNECT", "Directories in the ftp server are "
+ ftpDirs[i].getName());
}
FTPFile[] ftpdirs2 = ftpClient.listFiles(toppath);
for (int i = 0; i < ftpdirs2.length; i++) {
Log.d("CONNECT",
"File i need is " + ftpdirs2[i].getName());
}
}
For everybody who has the same problem. It works now with that code: (Thanks to user1106888)
try {
FTPClient ftpClient = new FTPClient();
ftpClient.connect(InetAddress.getByName("176.28.25.46"));
ftpClient.login("******", "******");
System.out.println("status :: " + ftpClient.getStatus());
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
try{
String toppath = new String();
FTPFile[] ftpDirs = ftpClient.listDirectories();
for (int i = 0; i < ftpDirs.length; i++) {
toppath = ftpDirs[0].getName();
System.out.println("Directory->: " + ftpDirs[i].getName());
}
FTPFile[] ftpdirs2 = ftpClient.listFiles(toppath);
for (int i = 0; i < ftpdirs2.length; i++) {
System.out.println("Files->: " + ftpdirs2[i].getName());
}
}catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
Use this code and it should help
FTPFile[] ftpDirs = mFTPClient.listDirectories();
for (int i = 0; i < ftpDirs.length; i++) {
toppath = ftpDirs[0].getName();
Log.d("CONNECT", "Directories in the ftp server are "
+ ftpDirs[i].getName());
}
FTPFile[] ftpdirs2 = mFTPClient.listFiles(toppath);
for (int i = 0; i < ftpdirs2.length; i++) {
Log.d("CONNECT",
"File i need is " + ftpdirs2[i].getName());
}
You can use CkFtp2 API to easily get the FTP directory listing information. Like the following:
CkFtp2 ftp = new CkFtp2();
int n = ftp.get_NumFilesAndDirs();
if (n < 0) {
outStr += ftp.lastErrorText() + "\n";
tv.setText(outStr);
setContentView(tv);
return;
}
if (n > 0) {
for (int i = 0; i <= n - 1; i++) {
// Display the filename
outStr += ftp.getFilename(i) + "\n";
// Display the file size (in bytes)
outStr += ftp.GetSize(i) + "\n";
// Is this a sub-directory?
if (ftp.GetIsDirectory(i) == true) {
outStr += ".. this is a sub-directory" + "\n";
}
outStr += "--" + "\n";
}
}