B4J Question 521 PROT P required - FTP

Nokia

Active Member
Licensed User
Longtime User
Does anybody know how to get around this error on ftp?

using jNet...
 

Nokia

Active Member
Licensed User
Longtime User
Please post the full error message and the relevant code.

B4X:
Sub Class_Globals
    Private fx As JFX
    Private ftp As FTP
    Private sftp As SFtp
    Private ctm As CustomTrustManager
    
    Private ftpUser As String
    Private ftpUserPswd As String
    Private ftpHost As String
    Private ftpPort As Int
    Private ftpPassive As Boolean
    Private ftpFolder As String
    Private ftpSSLimplicit As Boolean
    Private ftpSSLexplicit As Boolean
    
End Sub

Public Sub Initialize(Host As String, User As String, Password As String, _
                    port As Int, PassiveMode As Boolean, folder As String, Encryption As String)
                    
    ftpHost = Host
    ftpUser = User
    ftpUserPswd = Password
    ftpPort = port
    ftpPassive = PassiveMode
    ftpFolder = folder   
    
    If Encryption = "SSL - Implicit" Then
        ftpSSLimplicit = True
        ftpSSLexplicit = False
    Else if Encryption = "SSL - Explicit" Then
        ftpSSLimplicit = False
        ftpSSLexplicit = True
    Else
        ftpSSLimplicit = False
        ftpSSLexplicit = False
    End If
    
    ctm.InitializeAcceptAll
    ftp.SetCustomSSLTrustManager(ctm)
        
End Sub

Public Sub SendFileTest(FileandPath As String, ClassCalled As Object)
    
    Dim sPath As String = File.GetFileParent(FileandPath)
    Dim sFile As String = File.GetName(FileandPath)

    ftp.Initialize("FTPTest", ftpHost, ftpPort, ftpUser, ftpUserPswd)
    ftp.PassiveMode = ftpPassive
    ftp.UseSSL = ftpSSLimplicit
    ftp.UseSSLExplicit = ftpSSLexplicit
    ftp.UploadFile(sPath, sFile, False, ftpFolder & sFile)
        
End Sub
 
Upvote 0

Nokia

Active Member
Licensed User
Longtime User
Waiting for debugger to connect...
Program started.
java.lang.RuntimeException: Error uploading file.
521 PROT P required
at anywheresoftware.b4a.net.FTPWrapper$2.run(FTPWrapper.java:241)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
 
Upvote 0

Nokia

Active Member
Licensed User
Longtime User
I tried this:

B4X:
ftp.SendCommand("PROT", "P")

and got this error:

Waiting for debugger to connect...
Program started.
java.lang.RuntimeException: Error uploading file.
450 Unknown TLS error on data connection
at anywheresoftware.b4a.net.FTPWrapper$2.run(FTPWrapper.java:241)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
 
Upvote 0

Nokia

Active Member
Licensed User
Longtime User
IT seems that the PROT P command is being sent over in blue below. Error in red..

(000221)3/6/2020 20:38:09 PM - (not logged in) (192.168.1.104)> TLS connection established

(000221)3/6/2020 20:38:09 PM - (not logged in) (192.168.1.104)> USER TestT

(000221)3/6/2020 20:38:09 PM - (not logged in) (192.168.1.104)> 331 Password required for testt

(000221)3/6/2020 20:38:09 PM - (not logged in) (192.168.1.104)> PASS *******

(000221)3/6/2020 20:38:09 PM - testt (192.168.1.104)> 230 Logged on

(000221)3/6/2020 20:38:09 PM - testt (192.168.1.104)> PROT P

(000221)3/6/2020 20:38:09 PM - testt (192.168.1.104)> 200 Protection level set to P


(000221)3/6/2020 20:38:09 PM - testt (192.168.1.104)> TYPE I

(000221)3/6/2020 20:38:09 PM - testt (192.168.1.104)> 200 Type set to I

(000221)3/6/2020 20:38:09 PM - testt (192.168.1.104)> PORT 192,168,1,104,18,217

(000221)3/6/2020 20:38:09 PM - testt (192.168.1.104)> 200 Port command successful

(000221)3/6/2020 20:38:09 PM - testt (192.168.1.104)> STOR Test/Test_FTP_Upload.txt

(000221)3/6/2020 20:38:09 PM - testt (192.168.1.104)> 150 Opening data channel for file upload to server of "/Test/Test_FTP_Upload.txt"

(000221)3/6/2020 20:38:09 PM - testt (192.168.1.104)> Data connection TLS warning: SSL_accept: error 1 in SSLv2/v3 read client hello A

(000221)3/6/2020 20:38:09 PM - testt (192.168.1.104)> 450 Unknown TLS error on data connection

(000221)3/6/2020 20:38:09 PM - testt (192.168.1.104)> disconnected.
 
Upvote 0

Nokia

Active Member
Licensed User
Longtime User
You are testing it with a non-trusted certificate, right? You should test it with the accept all CustomTrustManager.

I have this line in my code

B4X:
    ctm.InitializeAcceptAll
    ftp.SetCustomSSLTrustManager(ctm)
 
Upvote 0

Nokia

Active Member
Licensed User
Longtime User
You are testing it with a non-trusted certificate, right? You should test it with the accept all CustomTrustManager.

Yes you are correct, I am testing with untrusted self signed cert..

here is my updated code:

B4X:
Sub Class_Globals
    Private fx As JFX
    Private ftp As FTP
    Private sftp As SFtp
    Private ctm As CustomTrustManager
    
    Private ftpUser As String
    Private ftpUserPswd As String
    Private ftpHost As String
    Private ftpPort As Int
    Private ftpPassive As Boolean
    Private ftpFolder As String
    Private ftpSSLimplicit As Boolean
    Private ftpSSLexplicit As Boolean

    'ftp
    ' C = Clear P=Protected
    Private sPROT_Action As String
        
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Host As String, User As String, Password As String, _
                    port As Int, PassiveMode As Boolean, folder As String, Encryption As String)
                    
    ftpHost = Host
    ftpUser = User
    ftpUserPswd = Password
    ftpPort = port
    ftpPassive = PassiveMode
    ftpFolder = folder   
    
    If Encryption = "SSL - Implicit" Then
        ftpSSLimplicit = True
        ftpSSLexplicit = False
        sPROT_Action = "P"
    Else if Encryption = "SSL - Explicit" Then
        ftpSSLimplicit = False
        ftpSSLexplicit = True
        sPROT_Action = "P"
    Else
        ftpSSLimplicit = False
        ftpSSLexplicit = False
        sPROT_Action = "C"
    End If
    
    ctm.InitializeAcceptAll
    ftp.SetCustomSSLTrustManager(ctm)
        
End Sub
Public Sub SendFileTest(FileandPath As String)
        
    Dim sPath As String = File.GetFileParent(FileandPath)
    Dim sFile As String = File.GetName(FileandPath)

    ftp.Initialize("FTPTest", ftpHost, ftpPort, ftpUser, ftpUserPswd)
    ftp.PassiveMode = ftpPassive
    ftp.UseSSL = ftpSSLimplicit
    ftp.UseSSLExplicit = ftpSSLexplicit
    ftp.SendCommand("PROT", sPROT_Action)
    'ftp.SendCommand("PBSZ", "0")
    ftp.UploadFile(sPath, sFile, False, ftpFolder & sFile)
    
End Sub

error in Explicit mode:

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:992)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:767)
at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:557)
at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1716)
at anywheresoftware.b4a.net.FTPWrapper$2.run(FTPWrapper.java:239)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:505)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
... 12 more

error in implicit mode:

Waiting for debugger to connect...
Program started.
java.lang.RuntimeException: Error uploading file.
450 Unknown TLS error on data connection
at anywheresoftware.b4a.net.FTPWrapper$2.run(FTPWrapper.java:241)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)


read out from fpt server:

(000010)3/8/2020 16:13:59 PM - (not logged in) (192.168.1.104)> Connected on port 21, sending welcome message...

(000010)3/8/2020 16:13:59 PM - (not logged in) (192.168.1.104)> 220-FileZilla Server 0.9.60 beta

(000010)3/8/2020 16:13:59 PM - (not logged in) (192.168.1.104)> 220-written by Tim Kosse ([email protected])

(000010)3/8/2020 16:13:59 PM - (not logged in) (192.168.1.104)> 220 Please visit https://filezilla-project.org/

(000010)3/8/2020 16:13:59 PM - (not logged in) (192.168.1.104)> AUTH TLS

(000010)3/8/2020 16:13:59 PM - (not logged in) (192.168.1.104)> 234 Using authentication type TLS

(000010)3/8/2020 16:13:59 PM - (not logged in) (192.168.1.104)> TLS connection established

(000010)3/8/2020 16:13:59 PM - (not logged in) (192.168.1.104)> USER TestT

(000010)3/8/2020 16:13:59 PM - (not logged in) (192.168.1.104)> 331 Password required for testt

(000010)3/8/2020 16:13:59 PM - (not logged in) (192.168.1.104)> PASS *******

(000010)3/8/2020 16:13:59 PM - testt (192.168.1.104)> 230 Logged on

(000010)3/8/2020 16:13:59 PM - testt (192.168.1.104)> PBSZ 0

(000010)3/8/2020 16:13:59 PM - testt (192.168.1.104)> 200 PBSZ=0

(000010)3/8/2020 16:13:59 PM - testt (192.168.1.104)> PROT P

(000010)3/8/2020 16:13:59 PM - testt (192.168.1.104)> 200 Protection level set to P

(000010)3/8/2020 16:13:59 PM - testt (192.168.1.104)> PROT P

(000010)3/8/2020 16:13:59 PM - testt (192.168.1.104)> 200 Protection level set to P

(000010)3/8/2020 16:13:59 PM - testt (192.168.1.104)> TYPE I

(000010)3/8/2020 16:13:59 PM - testt (192.168.1.104)> 200 Type set to I

(000010)3/8/2020 16:13:59 PM - testt (192.168.1.104)> PORT 192,168,1,104,42,82

(000010)3/8/2020 16:13:59 PM - testt (192.168.1.104)> 200 Port command successful

(000010)3/8/2020 16:13:59 PM - testt (192.168.1.104)> STOR Test/Test_FTP_Upload.txt

(000010)3/8/2020 16:13:59 PM - testt (192.168.1.104)> 150 Opening data channel for file upload to server of "/Test/Test_FTP_Upload.txt"

(000010)3/8/2020 16:14:00 PM - testt (192.168.1.104)> 450 TLS session of data connection has not resumed or the session does not match the control connection

(000010)3/8/2020 16:14:00 PM - testt (192.168.1.104)> disconnected.



(000012)3/8/2020 16:19:47 PM - (not logged in) (192.168.1.104)> Connected on port 32, sending welcome message...

(000012)3/8/2020 16:19:47 PM - (not logged in) (192.168.1.104)> 220-FileZilla Server 0.9.60 beta

(000012)3/8/2020 16:19:47 PM - (not logged in) (192.168.1.104)> 220-written by Tim Kosse ([email protected])

(000012)3/8/2020 16:19:47 PM - (not logged in) (192.168.1.104)> 220 Please visit https://filezilla-project.org/

(000012)3/8/2020 16:19:48 PM - (not logged in) (192.168.1.104)> TLS connection established

(000012)3/8/2020 16:19:48 PM - (not logged in) (192.168.1.104)> USER TestT

(000012)3/8/2020 16:19:48 PM - (not logged in) (192.168.1.104)> 331 Password required for testt

(000012)3/8/2020 16:19:48 PM - (not logged in) (192.168.1.104)> PASS *******

(000012)3/8/2020 16:19:48 PM - testt (192.168.1.104)> 230 Logged on

(000012)3/8/2020 16:19:48 PM - testt (192.168.1.104)> PROT P

(000012)3/8/2020 16:19:48 PM - testt (192.168.1.104)> 200 Protection level set to P

(000012)3/8/2020 16:19:48 PM - testt (192.168.1.104)> TYPE I

(000012)3/8/2020 16:19:48 PM - testt (192.168.1.104)> 200 Type set to I

(000012)3/8/2020 16:19:48 PM - testt (192.168.1.104)> PORT 192,168,1,104,42,119

(000012)3/8/2020 16:19:48 PM - testt (192.168.1.104)> 200 Port command successful

(000012)3/8/2020 16:19:48 PM - testt (192.168.1.104)> STOR Test/Test_FTP_Upload.txt

(000012)3/8/2020 16:19:48 PM - testt (192.168.1.104)> 150 Opening data channel for file upload to server of "/Test/Test_FTP_Upload.txt"

(000012)3/8/2020 16:19:48 PM - testt (192.168.1.104)> Data connection TLS warning: SSL_accept: error 1 in SSLv2/v3 read client hello A

(000012)3/8/2020 16:19:48 PM - testt (192.168.1.104)> 450 Unknown TLS error on data connection

(000012)3/8/2020 16:19:48 PM - testt (192.168.1.104)> disconnected.
 
Upvote 0

Nokia

Active Member
Licensed User
Longtime User
with more testing,, I can transfer files in explicit mode if I turn off "Require TSL session resumption on data connection when using PROT P"

but still get the 450 error on Implicit mode...
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top