EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Reading the beginning of the file.

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#10275
Posted: 06/04/2009 08:10:30
by Glenn Deneweth (Standard support level)
Joined: 05/28/2009
Posts: 9

In our FTP application we offer a preview mode which basically uses a tooltip to display the first couple hundred characters or so. I run this code and can not seem to get anything from it... any idea?

sFileHandle = SftpClient.OpenFile(strServerFileAndPath, SB_SFTP_OPENMODE_READ, Nothing)
Call SftpClient.Read(sFileHandle, 0, 0, 1024, strPreview)
SftpClient.CloseHandle (sFileHandle)

The strPreview is blank.
#10292
Posted: 06/04/2009 09:50:09
by Eugene Mayevski (EldoS Corp.)

Did you check whether sFileHandle was valid? Also, how was strPreview declared?


Sincerely yours
Eugene Mayevski
#10293
Posted: 06/04/2009 10:18:17
by Glenn Deneweth (Standard support level)
Joined: 05/28/2009
Posts: 9

Quote
Eugene Mayevski wrote:
Did you check whether sFileHandle was valid? Also, how was strPreview declared?


strPreview is just a string.
sFileHandle = 00000000

Thanks.
#10297
Posted: 06/04/2009 12:12:37
by Eugene Mayevski (EldoS Corp.)

I am not an expert in VB, but you should pass a VB array and not a string. Did you check the sample applications?


Sincerely yours
Eugene Mayevski
#10298
Posted: 06/04/2009 12:15:31
by Glenn Deneweth (Standard support level)
Joined: 05/28/2009
Posts: 9

Quote
Eugene Mayevski wrote:
I am not an expert in VB, but you should pass a VB array and not a string. Did you check the sample applications?


Thanks, that may be it. I did look at the sample but could not find one that used that. But it makes sense.
#10299
Posted: 06/04/2009 13:06:44
by Glenn Deneweth (Standard support level)
Joined: 05/28/2009
Posts: 9

Nope, I tried declaring as an array and also as a variant. I can't get anything to work. Any ideas?
#10300
Posted: 06/04/2009 13:14:02
by Eugene Mayevski (EldoS Corp.)

Hmm, the functionality always worked fine. I will try to reproduce the issue here now.


Sincerely yours
Eugene Mayevski
#10301
Posted: 06/04/2009 13:44:10
by Eugene Mayevski (EldoS Corp.)

Can you please tell me what exactly version of SecureBlackbox you are using?
#10302
Posted: 06/04/2009 13:48:20
by Glenn Deneweth (Standard support level)
Joined: 05/28/2009
Posts: 9

Version 7
#10303
Posted: 06/04/2009 14:01:16
by Eugene Mayevski (EldoS Corp.)

I've modified SimpleSftpDemo to have the following code:
Code
      Dim sFileHandle
      sFileHandle = SftpClient.OpenFile(currentDir & "/" & info.Name, SB_SFTP_OPENMODE_READ, Nothing)
      Dim strPreview
      Call SftpClient.Read(sFileHandle, 0, 0, 1024, strPreview)
      SftpClient.CloseHandle (sFileHandle)


And when debugging this code I could see the correct data in strPreview using QuickWatch. So maybe you are viewing or using strPreview in the wrong way? This is an array of byte, which should be either copied somewhere byte by byte or converted to the string in the same way. For example, using this function:

Code

Private Function ByteArr2Str(v As Variant) As String
    Dim I As Integer
    Dim B As Byte
    Dim C As String
    Dim result As String
    
    If VarType(v) = vbString Then
        ByteArr2Str = v
        Exit Function
    End If
    
    If VarType(v) <> vbArray + vbByte Then
        ByteArr2Str = ""
        Exit Function
    End If
    
    For I = LBound(v) To UBound(v)
        result = result + Chr(v(I))
    Next
    ByteArr2Str = result
End Function
Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.

Reply

Statistics

Topic viewed 3319 times

Number of guests: 2, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!