Next Topic

Previous Topic

Book Contents

Read

bool Read(TLuaSFTPClientHandle FileHandle,int iOffset,int iLen,string &sData)

Return value

Returns true if the operation was successful or false if otherwise.

Parameters

  • FileHandle - Handle of previously opened file.
  • iOffset - Offset in bytes where to read in file.
  • iLen - Length of data to read
  • sData - Variable to put data.

Remarks

Only text files can be read with this function.

Example

--KNM Lua API example (C) 2010 Kaseya AB
--Demonstrates the Lua SFTP client class

sftp = TLuaSFTPClient()
hFileHandle = TLuaSFTPClientHandle()

--Open the file
bOk = sftp:Open_ForRead("test.txt",hFileHandle)
if bOk == false then
	SetExitStatus("Open failed",false)
	return
end

sTemp = ""
--Read the first 20 bytes
bOk,sTemp = sftp:Read(hFileHandle,0,20,sTemp)
if bOk == false then
	SetExitStatus("Read failed",false)
	return
end
print(sTemp)