I have problem with download file from ftp server using library commons-net-3.6-ftp. Every time when I download always missing about 2kb with original size.
fun download(url: MapFragment){
try {
ftpClient?.changeWorkingDirectory("mapa/"+url.shortName)
listener!!.mapDownloadStarted()
val pathh = this.context!!.getExternalFilesDir(null)
val test = ftpClient?.listFiles()
test?.forEach {
val fileObj = File(pathh, "ptv/maps/" + it.name)
val desFileStream = BufferedOutputStream(FileOutputStream(fileObj))
val input: InputStream = ftpClient!!.retrieveFileStream(it.name)
try {
org.apache.commons.net.io.Util.copyStream(input,desFileStream)
desFileStream.flush()
desFileStream.close()
ftpClient!!.disconnect()
} catch (e: IOException) {
e.printStackTrace()
}
}
}catch (e: Exception) {
logE(e.toString())
}
}
configuration
val pass = context.getString(R.string.passFtp)
val loginFtp = context.getString(R.string.userFtp)
val serverFtp = context.getString(R.string.serverFtp)
val mFtpClient = FTPSClient()
val sc = SSLContext.getInstance("SSL")
val sr = java.security.SecureRandom()
sc.init(null, getTrustManager(), sr)
mFtpClient.connect(serverFtp, 62023)
mFtpClient.setDataTimeout(25000)
mFtpClient.bufferSize = 1024 * 1024
mFtpClient.setFileType(FTP.BINARY_FILE_TYPE)
mFtpClient.execPBSZ(0)
mFtpClient.execPROT("P")
mFtpClient.enterLocalPassiveMode()
if (mFtpClient.login(loginFtp, pass)) {
ftpClient = mFtpClient
} else {
ftpClient = null
}
I used retriveFile instead retrieveFileStream but everytime missing around 2kb
