goekie
goekie

Reputation: 9

Upload files from a folder to a FTP-Server. I've get two errors. How can I solve these errors?

I'm working on a FTP-Client.

I've already created an FTP-Client based by this one: Android How to upload a file via FTP With this code. It was possible to send a txt-File with an included string to my FTP-Server.

I've got pictures in my local folder "/sdcard/ftp/"

Now I'm trying to change the code, that it is possible that all the jpg-files in the folder will be send by ftp client.

    package de.android.datenuebertragung;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPConnectionClosedException;
import org.apache.commons.net.ftp.FTPFile;

import android.app.Activity;
import android.util.Log;

public class FTPManager extends Activity{
    FTPClient con = new FTPClient();{


    try
    {
        con.connect("host");
        if (con.login("user", "password"))
        {


            // in application never use hardcoded paths
            File folder = new File("/sdcard/ftp/");
            File tempFile = null;
            FTPFile[] tempFTPFile = null;

            //get all files in folder
            for(String fileInDir : folder.list()){
                tempFile = new File(fileInDir);
                tempFTPFile = con.listNames(tempFile.getFiles);

                if(tempFTPFile!=null || tempFTPFile.length<=0){
                    con.upload(fileInDir);
                }
            }


        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }


    try
    {
        con.logout();
        con.disconnect();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}
}

I've got two errors in the these marked words (getFiles and upload):

  1. tempFTPFile = con.listNames(tempFile.getFiles);
  2. con.upload(fileInDir);

The error in con.listNames(tempFile.getFiles) is: getFiles cannot be resolved or is not a field

and the another error in con.upload(fileInDir) is: The method upload(String) is undefined for the type FTPClient

I've tried the whole day to solve this problem. Hope someone can help me. Maybe post the changed and worked code. I'm an absolutley newbie in Android programming.

Upvotes: 0

Views: 2375

Answers (1)

Squonk
Squonk

Reputation: 48871

If you've pasted your code directly and there isn't a typo then it should be getFiles() and not getFiles in this line...

tempFTPFile = con.listNames(tempFile.getFiles);

Also, I suspect the default transfer mode will be ASCII (this is usually the case for any FTP client software).

Try calling...

con.setFileType(FTP.BINARY_FILE_TYPE);

...before attempting the uploads.

Upvotes: 0

Related Questions