Move Files after FTP Upload

Asked

Viewed 71 times

-1

My code uploads all images without folder, and it’s all OK! But what is it that needs to do FTP as images are uploaded to the path: "/storage/emulated/0/PicturesGRP/enviados";, storing the uploaded images and avoiding sending an image again in the next upload, someone knows how to do?

public void uploadFile() {
    FTPClient ftpClient = new FTPClient();
    try {
        ftpClient.connect(FTP_HOST);
        ftpClient.setSoTimeout(10000);
        ftpClient.enterLocalPassiveMode();
        if (ftpClient.login(FTP_USER, FTP_PASS)) {
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
            final File folder = new File("/storage/emulated/0/PicturesGRP/");
            ftpClient.changeWorkingDirectory( "/public_html/minas55/public/assets/os/3524/");

            for (final File fileEntry : folder.listFiles()) {
                try {
                    FileInputStream fs = new FileInputStream(fileEntry);
                    if (!fileEntry.isDirectory()) {
                        String fileName = fileEntry.getName();
                        ftpClient.storeFile(fileName, fs);
                        fs.close();
                        Toast.makeText(getApplicationContext(), "Sincronização com Sucesso !", Toast.LENGTH_SHORT).show();
                        String horarioSync2 = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy ").format(System.currentTimeMillis());
                        syncHorario.setText(horarioSync2);
                    }
                } catch (Exception e) {
                    String horarioSync2 = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy ").format(System.currentTimeMillis());
                    syncHorario.setText(horarioSync2);
                }
            }
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

1 answer

0

The question got a little confusing, but if the problem is moving folder files try using apache Camel, it is simple and works well.

  • I need it to create on the Folder server at the time of FTP

Browser other questions tagged

You are not signed in. Login or sign up in order to post.