package `in`.techware.carrefour.util

import android.util.Base64
import android.util.Log
import it.sauronsoftware.ftp4j.FTPClient
import java.io.File
import java.nio.charset.Charset

/**
 * Created by Jemsheer K D on 26 July, 2018.
 * Package in.techware.carrefour.util
 * Project Carrefour
 */
object FTPUtil {

    private val TAG: String = "FTPUtil"

    fun uploadFile(filePath: String): Boolean {
        try {
            val mFtpClient = FTPClient()
            mFtpClient.connect(AppConstants.FTP_SEND_SERVER, 21)
            var password = String(Base64.decode(AppConstants.FTP_SEND_PASSWORD, Base64.DEFAULT), Charset.defaultCharset());
            mFtpClient.login(AppConstants.FTP_SEND_USERNAME, password)
            Log.i(TAG, "FTPUtil PASSWORD : $password");
            mFtpClient.type = FTPClient.TYPE_BINARY
            mFtpClient.changeDirectory("/")

            mFtpClient.upload(File(filePath))
            mFtpClient.disconnect(true)
        } catch (e: Exception) {
            e.printStackTrace()
            return false
        }
        return true
    }

}
