Spanish (SOLUCIONADO) SMB Actual?

TheFalcon

Active Member
Licensed User
Longtime User
Buenas a tod@s, estoy intentando enlazar una APK con un software pc, y he visto que el modo a usar es SMB , pero los post que encuentro son de 2012 /13 y no se si hay algún modo mas actual, ya que no encuentro nada de smb mas actual (aparte el que encontré de 2012 me dice que es versión obsoleta para mi dispositivo)

Agradecería si alguien tiene un ejemplo, o un enlace a donde pueda orientarme sobre la conexión etc. etc.

Muchas gracias como siempre
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
te recomiendo que le eches un ojo a b4a bridge:
el codigo fuente es libre y pues ya ves que funciona muy bien como enlace.
 

TheFalcon

Active Member
Licensed User
Longtime User
Gracias, ese es el mismo que se usa para instalar las aplicaciones en el móvil, no se si ha sido mejorado, pero yo lo que quiero por ejemplo es desde una aplicación conectar a un PC y traerse una archivo o al revés enviar del dispositivo un archivo al pc
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
con b4a bridge, estas moviendo el archivo APK que compilaste en tu pc y lo pasas a el celular, lo mismo podrias hacer al reves. pero bueno es un ejemplo.
 

TheFalcon

Active Member
Licensed User
Longtime User
En resumen lo que necesito es poder añadir datos a una base de datos del PC desde una aplicación android, y poder mandar archivos entre ambos, y por lo visto ley que es con SMB pero no encuentro nada ACTUAL , ningun ejemplo .
 

TheFalcon

Active Member
Licensed User
Longtime User
Igual te interesa JRDC2 para una base de datos o B4Xaserializator para comunicar b4j y b4a
No conozco esas librerías, ¿me valdrían para lo que quiero? modificar la Base de datos del PC desde el Android y pasar archivos entre ellos?.
Gracias ante todo
 

josejad

Expert
Licensed User
Longtime User
Hola:

SMB, ejemplo de 2019 (no lo he probado nunca)

Otra opción sería que instalaras un gestor FTP (tipo FILEZILLA) en el PC, y usaras FTP para transferir archivos:


JRDC2



saludos,
 

TheFalcon

Active Member
Licensed User
Longtime User
José cuanto tiempo, muchas gracias , estoy siguiendo el tutorial que me paso el compañero Rafa, y ese mismo que me pones traducido por tí , a ver si lo hago funcionar, y comento.
 

TheFalcon

Active Member
Licensed User
Longtime User
Un Apunte, ¿Se puede usar con SQL ? es decir yo mi aplicación usa bases de datos SQLite, también se puede usar así, o ha de ser en Mysql?, es quew no consigo extrapolar los videos y tutoriales para arrancar el servidor java

Yo en la linea que pone el ejemplo

B4X:
#AdditionalJar: mysql-connector-java-5.1.27-bin

añado
B4X:
#AdditionalJar: sqlite-jdbc-3.43.0.0

que seria el SQLite JDBC Driver y me bajo el archivo sqlite-jdbc-3.43.0.0.jar
 

MrKim

Well-Known Member
Licensed User
Longtime User
Here is some code I am using that definitely works. B4A/B4J. IT has some SQL stuff in it to get the file I want but you can pull that out. Note the B4J does not use SMB but might be helpful for testing.
Note: YOU MUST ENABLE SMB1 IN WINDOWS AND THIS IS A KNOWN SECURITY ISSUE. You will see a lot of advice that says don't do it.
1696228416131.png

B4X:
#If B4A

Private Sub TestFileAccessBtn_Click
Try
    'SELECT TOP 100 Pmp_PictureName FROM PartMasterPics WHERE Pmp_PrintOnTrav = 1;
    ProgressDialogShow("Getting picture file name from server.")
    Wait For (MP.Ethernet.Getdata("PMPicTest", Null)) Complete (DataRows As List)
    If Not(DataRows.Get(0).As(String).EqualsIgnoreCase("Request Failed")) Then
        If DataRows.Size > 0 Then
            Dim Picmap As Map = DataRows.Get(Rnd(0, DataRows.Size - 1))
            If UseSQLForFilesCB.Checked Then
                ProgressDialogShow("File(s) found. Attempting to get the file VIA SQL.")
                Wait For (MP.Ethernet.Getdata("GetDocFileBinary", Array(Picmap.Get("Pmp_PictureName")))) Complete (DataRows As List)
                If Not(DataRows.Get(0).As(String).Contains("Request Failed")) Then
                    Dim TMap As Map = DataRows.Get(0)
                    If TMap.Get("Result").As(String).EqualsIgnoreCase("SUCCESS") Then
                            Dim Buffer() As Byte  = TMap.Get("Picture")
                        Dim InputStream1 As InputStream
                        InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
                        #If B4J
                            Dim Bmp As Image
                            Bmp.Initialize2(InputStream1)
                        #Else
                            Dim Buffer() As Byte  = TMap.Get("Picture")
                            Dim InputStream1 As InputStream
                            InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
                            Dim Bmp As Bitmap
                            Bmp.Initialize2(InputStream1)
                            InputStream1.Close
                        #End If
                        IMV.Bitmap = Bmp
                        IMV.ResizeMode = "FIT"
                        IMV.mBase.Visible = True
                        Wait For(MP.xui.MsgboxAsync($"File ${Picmap.Get("Pmp_PictureName")} was successfully copied from the network and loaded as an image. You should have access to pictures and documents."$, "SUCCESS!")) Msgbox_Result (RW As Int)
                        IMV.mBase.Visible = False
                    Else
                        xui.MsgboxAsync($"SQL Error retrieving Picture File Binary for ${Picmap.Get("Pmp_PictureName")} from Server

The SQL error is:

${TMap.Get("Result")}"$, "Error in TestFileAccessBtn_Click")
                    End If
                Else
                    xui.MsgboxAsync($"Error retrieving Picture File Binary ${Picmap.Get("Pmp_PictureName")} from Server"$, "Error in TestFileAccessBtn_Click")
                End If
            Else
                ProgressDialogShow("File(s) found. Checking if we can see the file on the network.")
                #IF B4i
                    Main.DocsDir = $"${File.DirLibrary}/Docs"$
                    File.MakeDir(File.DirLibrary, "Docs")
                #Else
                    Main.DocsDir = $"${File.DirInternal}/Docs"$
                    File.MakeDir(File.DirInternal, "Docs")
                #End If
                MP.DCUTs.SMB1.SetCredentials(FileAccessUserName.Text, FileAccessPassword.Text, "")
                MP.DCUTs.SMB1.Initialize("SMB1")
                Dim FN As String, Pth As String
                FN = Picmap.Get("Pmp_PictureName").As(String).Replace("\","/")
                Pth = FN.SubString2(0, (FN.LastIndexOf("/") + 1))' & "/"
                FN = FN.SubString2(FN.LastIndexOf("/") + 1, FN.Length)
                MP.DCUTs.SMB1.ListFiles("smb:" & Pth , FN)
                Wait For SMB1_ListCompleted(Url As String, Success As Boolean, Entries() As SMBFile)
                If Success Then
                    If Entries.Length > 0 Then
                        ProgressDialogShow("File "  & Pth & FN & " was found on the network! Attempting to copy the file to the tablet.")
                        xui.MsgboxAsync("File "  & Pth & FN & " was found on the network! Attempting to copy the file to the tablet.", "")
                        MP.DCUTs.SMB1.DownloadFile("smb:" & Pth , FN, Main.DocsDir, FN)
                        Wait For SMB1_DownloadCompleted (Url As String, RemoteFile As String, Success As Boolean)
                        If Success Then
                            xui.MsgboxAsync($"File "  & ${Pth} & ${FN} was successfully copied from the network. You should have access to pictures and documents."$, "SUCCESS!")
                        Else
                            xui.MsgboxAsync($"UNABLE to copy File "  & ${Pth} & ${FN} locally. Make sure you have all appropriate rights to copy files. Make sure that SMB1 is enabled on your document server."$, "COPY FAILED")
                        End If
                    Else
                        xui.MsgboxAsync($"File "  & ${Pth} & ${FN} was NOT found on the network! It is possible that the file does not exist. You can try again and a diferent file will be chosen at randon. If that fails then we don't have appropriate rights to the server. Make sure that SMB1 is enabled on your document server."$, "File not Found")
                    End If
                Else
                    xui.MsgboxAsync($"There was an error tring to locate the file "  & ${Pth} & ${FN} on the network! It is possible that the file does not exist. You can try again and a diferent file will be chosen at randon. If that fails then we don't have appropriate rights to the server. Make sure that SMB1 is enabled on your document server."$, "File not Found")
                End If
            End If
        Else
            xui.MsgboxAsync($"No Print On Traveler Picture FileNames found in PartmasterPics"$, "Error in TestFileAccessBtn_Click")
        End If
    Else
        xui.MsgboxAsync($"Error retrieving ANY Picture FileNames from PartmasterPics"$, "Error in TestFileAccessBtn_Click")
    End If      
    ProgressDialogHide
Catch
    ProgressDialogHide
    xui.MsgboxAsync(LastException.Message.SubString2(0, Min(LastException.Message.Length, 500)), "Error in TestFileAccessBtn_Click")
End Try

End Sub
#Else If B4J
Private Sub TestFileAccessBtn_Click
Try
    'Dim SMB1 As SMB
    'SELECT TOP 100 Pmp_PictureName FROM PartMasterPics WHERE Pmp_PrintOnTrav = 1;
'    ProgressDialogShow("Getting picture file name from server.")
    Toast.Show("Getting picture file name from server.", Null)
    Wait For (MP.Ethernet.Getdata("PMPicTest", Null)) Complete (DataRows As List)
    If Not(DataRows.Get(0).As(String).EqualsIgnoreCase("Request Failed")) Then
        If DataRows.Size > 0 Then
            Dim Picmap As Map = DataRows.Get(Rnd(0, DataRows.Size - 1))
            If UseSQLForFilesCB.Checked Then
                Toast.show("File(s) found. Attempting to get the file VIA SQL.", Null)
                Wait For (MP.Ethernet.Getdata("GetDocFileBinary", Array(Picmap.Get("Pmp_PictureName")))) Complete (DataRows As List)
                If Not(DataRows.Get(0).As(String).Contains("Request Failed")) Then
                    Dim TMap As Map = DataRows.Get(0)
                    If TMap.Get("Result").As(String).EqualsIgnoreCase("SUCCESS") Then
                            Dim Buffer() As Byte  = TMap.Get("Picture")
                        Dim InputStream1 As InputStream
                        InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
                        #If B4J
                            Dim Bmp As Image
                            Bmp.Initialize2(InputStream1)
                        #Else
                            Dim Buffer() As Byte  = TMap.Get("Picture")
                            Dim InputStream1 As InputStream
                            InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
                            Dim Bmp As Bitmap
                            Bmp.Initialize2(InputStream1)
                            InputStream1.Close
                        #End If
                        IMV.Bitmap = Bmp
                        IMV.ResizeMode = "FIT"
                        IMV.mBase.Visible = True
                        Wait For(MP.xui.MsgboxAsync($"File ${Picmap.Get("Pmp_PictureName")} was successfully copied from the network and loaded as an image. You should have access to pictures and documents."$, "SUCCESS!")) Msgbox_Result (RW As Int)
                        IMV.mBase.Visible = False
                    Else
                        xui.MsgboxAsync($"SQL Error retrieving Picture File Binary for ${Picmap.Get("Pmp_PictureName")} from Server

The SQL error is:

${TMap.Get("Result")}"$, "Error in TestFileAccessBtn_Click")
                    End If
                Else
                    xui.MsgboxAsync($"Error retrieving Picture File Binary ${Picmap.Get("Pmp_PictureName")} from Server"$, "Error in TestFileAccessBtn_Click")
                End If
            End If
        Else
            xui.MsgboxAsync($"No Print On Traveler Picture FileNames found in PartmasterPics"$, "Error in TestFileAccessBtn_Click")
        End If
    Else
        xui.MsgboxAsync($"Error retrieving ANY Picture FileNames from PartmasterPics"$, "Error in TestFileAccessBtn_Click")
    End If      
Catch
    xui.MsgboxAsync(LastException.Message.SubString2(0, Min(LastException.Message.Length, 500)), "Error in TestFileAccessBtn_Click")
End Try

End Sub
#End If

I should also mention the code Starting HERE:
B4X:
Wait For (MP.Ethernet.Getdata("GetDocFileBinary
first looks to see if we can get the file using an SQL server function. This is the preferred method since it is more secure.
 
Last edited:

vecino

Well-Known Member
Licensed User
Longtime User
Uno de mis programas utiliza SMB, sin problemas, y desde hace años.
Luego cambié a SMB2, casi no tuve que hacer nada, y ahí sigue trabajando.
 

fabian

Member
Licensed User
Longtime User
Si usas Windows 10 o 11 tienes que habilitar samba version 1 en windows desde el panel de control , sino no es compatible con la libreria. La otra opcion es usar ftp .
 

vecino

Well-Known Member
Licensed User
Longtime User
Si usas Windows 10 o 11 tienes que habilitar samba version 1 en windows desde el panel de control , sino no es compatible con la libreria. La otra opcion es usar ftp .

En principio no hay problema, yo lo uso y no he tenido que configurar nada en ningún windows.
De todas formas, si se usa SMB (y no SMB2) puede ser necesario habilitarlo en el panel de control:

cuH0fH6.png
 

MrKim

Well-Known Member
Licensed User
Longtime User
One of my programs uses SMB, without problems, and for years.
Then I changed to SMB2, I hardly had to do anything, and it's still working there.
Where did you get SMB2? (I am assuming we are talking Android here.) When I originally did this it wasn't available. You have a code example?
 

MrKim

Well-Known Member
Licensed User
Longtime User
In the link posted by Jose J. Aguilar
Unfortunately, as I read it. It only supports Android to Windows. My primary need is Windows to Android.
And before you reply I know and use the other options but for some customers SMB is the easiest so it would be nice not to have to enable SMB1.
 
Last edited:
Top