I want to transfer a file to a ftp server wich use explicite TLS/SSL.

When I connect with File Zilla and choose as servertype: FTPES - FTP over 
explicite TLS/SSL i can connect and upload files.

I try to upload some files to a ftp server with explicite TLS.
My code work until the it upload the files. It throws an IOException.
The last response from the server (getReplyStrings()) is

[150 Accepted data connection]



In the upload folder it generates a empty file. I have no access to the FTP 
log on the server.

FTPSClient ftp = new FTPSClient("TLS",false);
ftp.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
KeyManagerFactory kmf = null;
try {
    kmf = 
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    kmf.init(null, null);
    KeyManager km = kmf.getKeyManagers()[0];
    ftp.setKeyManager(km);
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
} catch (UnrecoverableKeyException e) {
    e.printStackTrace();
} catch (KeyStoreException e) {
    e.printStackTrace();
}

ftp.setBufferSize(1024 * 1024);
ftp.setConnectTimeout(100000);

try {
    ftp.connect("domain.com");
    ftp.setSoTimeout(1000000);
    if (ftp.login("login", "passsword")) {
        ftp.execPBSZ(0);
        ftp.execPROT("P");
        ftp.changeWorkingDirectory("/");
        if (ftp.getReplyString().contains("250")) {
            ftp.setFileType(FTP.BINARY_FILE_TYPE);
            ftp.enterLocalPassiveMode();
            BufferedInputStream buffIn;
            for(File file : files) {
                Log.d("DEBUG","Uploading: " + file.getPath());
                buffIn = new BufferedInputStream(new 
FileInputStream(file.getAbsolutePath()));
                boolean result = ftp.storeFile(file.getName(), buffIn);
                buffIn.close();
            }
        }
        ftp.logout();
    }
    ftp.disconnect();
} catch (IOException e) {
    System.out.println(Arrays.toString(ftp.getReplyStrings()));
    System.out.println(e);
    Log.d("DEBUG", Arrays.toString(e.getStackTrace()));
}


This are the last lines from logcat:


09-14 19:54:01.821 18538-18571/com.google.observer D/DEBUG: Uploading: 
/storage/emulated/0/temp/1_20160709_162505.jpg.jpg09-14 19:54:02.871 
18538-18571/com.google.observer I/System.out: [150 Accepted data 
connection]09-14 19:54:02.871 18538-18571/com.google.observer I/System.out: 
javax.net.ssl.SSLException: Write error: ssl=0x7f9d8c6200: I/O error during 
system call, Broken pipe09-14 19:54:02.881 18538-18571/com.google.observer 
D/DEBUG: [com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method),
com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:877),
java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185),
java.io.BufferedOutputStream.flush(BufferedOutputStream.java:85), 
java.io.FilterOutputStream.close(FilterOutputStream.java:61), 
java.io.BufferedOutputStream.close(BufferedOutputStream.java:152), 
org.apache.commons.net.ftp.FTPClient._storeFile(FTPClient.java:666), 
org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:624), 
org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1976), 
com.google.observer.Ftp.upload(Ftp.java:66), 
com.google.observer.MainActivity$1.run(MainActivity.java:30)]




-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/c00cd6fa-d64e-48ff-b2cb-01a81f9a4bb2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to