Page 1 of 1

Copy Files to a Samba Share

Posted: Wed Aug 02, 2006 10:13 am
by clipper
I want to write a PB Win Software, which have to copy files to a Samba Directory.

The User who was logged in at the WinPC and who works with my PB Software doesn´t have any rights to the Samba-Share! It is not allowed that the user has access to this directory, except to copy a file with my software!

So my Software must copy the files with a account who has this rights to write a file in the samba share.

How can I do this?
A function like CopyFile(source$,dest$,username$,password$) ;-) doesn´t exist.

Posted: Wed Aug 02, 2006 3:03 pm
by Droopy
Try this ( PB 3.94 Code ) :

Code: Select all

ProcedureDLL WNetAddConnectionNT(Username.s,Password.s,ShareName.s,DriveLetter.s,Persistant.l)
  
  ;/ Username / Password
  ;/ Sharename : \\Server\Share
  ;/ DriveLetter : F:
  ;/ Persistant : #True or #False
  ;/ Return 1 if success or 0 if fail
  
  lpNetResource.NETRESOURCE
  lpNetResource\dwtype=1 ; RESOURCETYPE_DISK
  lpNetResource\lpLocalName=@DriveLetter
  lpNetResource\lpRemoteName=@ShareName
  
  OpenLibrary(0,"Mpr.dll")
  retour=CallFunction(0,"WNetAddConnection2A",lpNetResource,Password,Username,Persistant)
  CloseLibrary(0)
  
  If retour=0 : retour=1 : Else : retour=0 : EndIf
  ProcedureReturn retour
  
EndProcedure


ProcedureDLL WNetCancelConnection(DriveLetter.s,force.l)
  
  ; Driveletter : Ex F:
  ; Force = #True or #False ( Deconnect when file is in use )
  
  OpenLibrary(0,"Mpr.dll")
  retour=CallFunction(0,"WNetCancelConnectionA",DriveLetter,force)
  CloseLibrary(0)
  If retour=0 : retour=1 : Else : retour=0 : EndIf
  ProcedureReturn retour
EndProcedure

Posted: Thu Aug 03, 2006 10:35 am
by clipper
Thanks for the code droopy! It works fine!

but it will be my last recource because I don´t want to assign a drive letter with code overhead (Letter free ....).