B4J Question Nas Login

PatrikCavina

Active Member
Licensed User
Longtime User
Hi to everyone,
I need to connect to NAS in my LAN, but must insert credential to access.
I need this because i want to write file inside it.
What is the most efficient method to use?
I tried Http connection and smb but i think that i don't have the necessary knowledge
 

Knoppi

Active Member
Licensed User
Longtime User
Libraries:
jNet (build in)
SMB http://www.b4x.com/forum/additional-libraries-classes-official-updates/17180-smb-library-2.html#post166766
B4X:
Sub Process_Globals
    Dim mySMB As SMB
    Dim User As String = "YourUsername"
    Dim Passwd As String = "YourPassword"
    Dim Domain As String = ""
    Dim smbURL As String = "smb://YourDevice/backup/"  'YourDevice= localIP or DeviceName

    Dim myFTP As FTP
    Dim Host As String = "YourIP"  ' lan or wan
    Dim Port As Int = 21  'Standard port
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    WriteViaSMB
    WriteViaFTP
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub WriteViaFTP
    myFTP.Initialize( "myFTP", Host, Port, User, Passwd)
  
    myFTP.UploadFile( File.DirAssets, "testfile.txt", True, "/backup/testftp.txt")
    wait for myFTP_UploadCompleted (ServerPath As String, Success As Boolean)
    Log( Success)
End Sub

Sub WriteViaSMB
    mySMB.Initialize( "mySMB")
    mySMB.SetCredentials( User, Passwd, Domain)
      
    mySMB.UploadFile( File.DirAssets, "testfile.txt", smbURL, "testsmb.txt")
    wait for mySMB_UploadCompleted (Url As String, RemoteFile As String, Success As Boolean)
    Log( Success)
End Sub
 
Last edited:
Upvote 0
Top