B4J Question SMB copy network files

wyatt420

Member
Licensed User
Longtime User
Hi, I am trying to write a program that copies files from one PC (via user inputted IP address) to the local machine.

In the other computer there are 66 files, but only 33 files copy over and most of the are 0 KB, with no errors returned.

The authentication is working fine, as I can run SMB.listfiles and get details.

Any ideas on what I could be doing wrong?

B4X:
Sub SMBtest
    SMB1.Initialize("SMB1")
    SMB1.SetCredentials("username", "password", "")
    SMB1.ListFiles("smb://" & txtPCname.Text & "/testHost/", "")
End Sub

B4X:
Sub SMB1_ListCompleted(Url As String, Success As Boolean, Entries() As SMBFile)
    If Not(Success) Then 
          Log(LastException)
        lblCntErr.Text = "ERROR CONNECTING TO " &txtPCname.Text 
      Else
      lblCntSucc.Text = "CONNECTED"
    For i = 0 To Entries.Length - 1
        SMB1.Downloadfile(Entries(i).Parent, Entries(i).Name, "c:\test2\", Entries(i).Name)
   Next
 End If
End Sub
 

wyatt420

Member
Licensed User
Longtime User
hi Erel, currently i have no DownloadCompleted.
Would i use this to verify the integrity of the original to the downloaded?

I have modified the original folder to only host a couple small files (~200KB) and it works, it just seems having more files causes the issue.

I thought the looping For statement could be causing the process to jam up and not download all data, and tried a delay to allow data to copy across.

thanks
 
Upvote 0

wyatt420

Member
Licensed User
Longtime User
thanks Erel, I have checked, the first three files copied correctly however, raising exception:
(Exception) Not initialized

the remaining files copied over at 0KB with exception:
(TransportException) jcifs.util.transport.TransportException: Transport1 timedout waiting for response to SmbComReadAndX[command=SMB_COM_READ_ANDX,received=false,errorCode=0,flags=0x0018,flags2=0xC803,signSeq=0,tid=2055,pid=36310,uid=6146,mid=297,wordCount=12,byteCount=0,andxCommand=0xFF,andxOffset=0,fid=16411,offset=12478,maxCount=3906,minCount=3906,openTimeout=-1,remaining=0,offset=12478]
 
Upvote 0

coyote

Member
Licensed User
Longtime User
Hi,

is it possible to get a progressbar working for smb (download, upload) and cancel the file transfer?

Thx, Coyote
 
Upvote 0

coyote

Member
Licensed User
Longtime User
Thank you Erel,
I've tried to get running the counting part.
But something is wrong, I guess the initialization.

The download is ok, but the Log Output (Sub SMBTimer_Tick) is: 0 Do you have any ideas?

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private SMB1 As SMB
    Private btDownload As Button
    Private btCancel As Button
    Private pBar As ProgressBar
    Private label1 As Label
    Private cout As CountingOutputStream
    Private Timer1 As Timer
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
   
End Sub
Sub btCancel_Action
    If cout.IsInitialized = True Then
        cout.Close
        cout.Flush
    Else
        Log ("cout not init")
    End If
End Sub
Sub btDownload_Action
   
    Timer1.Initialize("SMBTimer",500)
    Dim out As OutputStream
    out.InitializeToBytesArray(0)
    out = File.OpenOutput(File.DirApp, "xxxx.zip", False)
   
    SMB1.Initialize("SMB1")
    SMB1.DownloadFile2("smb://192.xxx.xxx.xxx/public/", "xxxx.zip", out, True)
   
    cout.Initialize(out)
    Timer1.Enabled = True
End Sub
Sub SMB1_DownloadCompleted (Url As String, RemoteFile As String, Success As Boolean)
    If Not(Success) Then
      Log("Download failed : " & LastException)
    Else
        Log("Download : " & RemoteFile & " downloaded")
       
    End If
    cout.Flush
    Timer1.Enabled = False
End Sub
Sub SMBTimer_Tick
    Log(cout.Count)
End Sub

When I start the download (CountingOutputStream will Initialize ) and cancel it, how can i reset/stop the initialization?
So I know there is no download started.

Oh man...Many Thanks, Coyote
 
Upvote 0
Top