EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Access violation in TElSimpleSFTPClient.Read

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
#5023
Posted: 02/15/2008 10:50:13
by Jens Weber (Standard support level)
Joined: 05/15/2007
Posts: 5

Hi,

I am using SBB 5.2.124 as SFTP client and VShell 2.6.0 as SFTP server on a Windows machine. Since I want to process the data before writing it to disk, I am using the methods OpenFile, Read and CloseHandle.

But now I am stuck. Delphi bugs me with an access violation in TElSimpleSFTPClient.Read.

My code works fine with an OpenSSH server on Linux. I could also download the file on the VShell server using the DownloadFile method of the same TElSimpleSFTPClient object.

Could you please help me finding the error in my code?

Code
procedure TForm1.Button3Click(Sender: TObject);
  var
    sHandle: String;
    aBuffer: array of Char;
    iOffset: Int64;
    iBufferRead: Integer;
  const
    BUFFERSIZE = 262144;
begin
  try
    ElSimpleSFTPClient1.AuthenticationTypes :=
            SSH_AUTH_TYPE_PASSWORD;
    ElSimpleSFTPClient1.Open;
    sHandle := ElSimpleSFTPClient1.OpenFile(sFileName,
            [fmRead, fmText],
            nil);
    SetLength(aBuffer, BUFFERSIZE);
    iOffset := 0;
    repeat
      [COLOR=red]iBufferRead := ElSimpleSFTPClient1.Read(sHandle, iOffset, aBuffer, BUFFERSIZE);[/COLOR]
      // ...
    until (iBufferRead < BUFFERSIZE);
  finally
    ElSimpleSFTPClient1.CloseHandle(sHandle);
    ElSimpleSFTPClient1.Close;
  end;
  ShowMessage('Done.');
end;


The VShell log looks like this, if the access violation occurs:
Code
16:37:42,conn,00076: Connection accepted from [...].
16:37:43,auth,00076: none for user [...] rejected because it is unavailable.
16:37:43,auth,00076: password for user [...] accepted.
16:37:43,conn,00076: Session channel open request accepted.
16:37:43,conn,00076: Received request to start subsystem sftp (Built-in Subsystem)
16:37:43,sftp,00076: Sftp subsystem initialized; remote version is 4.
16:37:43,sftp,00076: Sending VERSION packet to remote (4)
16:37:47,sftp,00076: Sftp subsystem terminated.
16:37:47,conn,00076: [COLOR=red]The transport closed cleanly, but there were still channels active.
All channels are being closed.[/COLOR]

16:37:47,sftp,00076: [COLOR=green][...] has accessed [...] for read 14567 bytes transferred.[/COLOR]
16:37:47,conn,00076: Connection closed.


And it looks like this, when the file is downloaded correctly using DownloadFile:
Code
16:58:08,conn,00077: Connection accepted from [...].
16:58:08,auth,00077: none for user [...] rejected because it is unavailable.
16:58:08,auth,00077: password for user [...] accepted.
16:58:08,conn,00077: Session channel open request accepted.
16:58:08,conn,00077: Received request to start subsystem sftp (Built-in Subsystem)
16:58:08,sftp,00077: Sftp subsystem initialized; remote version is 4.
16:58:08,sftp,00077: Sending VERSION packet to remote (4)
16:58:08,sftp,00077: [COLOR=green][...] has accessed [...] for read 14567 bytes transferred.[/COLOR]
16:58:08,sftp,00077: Sftp subsystem terminated.
16:58:08,conn,00077: Session channel has been closed (pid: none).
16:58:08,conn,00077: The transport was aborted with a disconnect packet.  Detail: Disconnected by application.
Connection closed


Thank you in advance,

Jens.
#5025
Posted: 02/15/2008 11:11:11
by Ken Ivanov (EldoS Corp.)

Please try to replace the line

iBufferRead := ElSimpleSFTPClient1.Read(­sHandle, iOffset, aBuffer, BUFFERSIZE);

with

iBufferRead := ElSimpleSFTPClient1.Read(­sHandle, iOffset, @aBuffer[0], BUFFERSIZE);

and check if it changes something. If it doesn't, please provide us the complete call stack of the moment when AV is thrown.
#5065
Posted: 02/19/2008 07:13:42
by Jens Weber (Standard support level)
Joined: 05/15/2007
Posts: 5

Hi,

your suggestion did not change anything.
The AV only occurs, when I debug my code within Delphi. So the exception seems to be treated in your code.
When I run the code without debugging it, the program would freeze consuming 100% of the CPU.

I also found out that the error does not occur when I drop the "fmText" flag when calling the OpenFile method.

Since I am doing my own line break conversion, I am fine without the fmText parameter.

Best regards,

Jens.
#5066
Posted: 02/19/2008 07:20:38
by Eugene Mayevski (EldoS Corp.)

Do I understand you right that the problem only happens when you open the file in text mode?


Sincerely yours
Eugene Mayevski
#5067
Posted: 02/19/2008 07:24:47
by Eugene Mayevski (EldoS Corp.)

I've moved your initial message to HelpDesk so that our developers could test it and introduce the necessary fixes.


Sincerely yours
Eugene Mayevski
Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.

Reply

Statistics

Topic viewed 3905 times

Number of guests: 1, 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!