Page 1 of 1

ScSFTPClient.OpenFile and WriteFile problems

Posted: Fri 17 Sep 2010 07:19
by EAC
Hi, I'm a SFTP and SecureBridge newbee and having problems with following code after succesfull SSHClient and SFTPClient connection:

try
repeat
ScSFTPClient1.ReadDirectory(RemoteHandle);
until ScSFTPclient1.EOF;
finally
ScSFTPClient1.CloseHandle(RemoteHandle);
end;
ProgressBar1.Visible:=True;
LocalHandle:=FileOpen(LocalFile,fmOpenRead);

//up to here everything is ok

RemoteHandle:=ScSFTPClient1.OpenFile
(ScSFTPClient1.RetrieveAbsolutePath('.')+remotefile,[FoCreate]);
try
SetLength(Buffer, ScSFTPClient1.WriteBlockSize);
Offset := 0;
repeat
Count:=FileRead(LocalHandle,Buffer,ScSFTPClient1.WriteBlockSize);
if Count > 0 then
ScSFTPClient1.WriteFile(RemoteHandle, Offset, Buffer, 0, Count);
Offset := Offset + Count;
until Offset>=ProgressBar1.Max; //max = local filesize
result:=True;
finally
FileClose(LocalHandle);
ScSFTPClient1.CloseHandle(RemoteHandle);
end;

When compiling this I get the following errors:
[Pascal Error] Main.pas(172): E2250 There is no overloaded version of 'OpenFile' that can be called with these arguments
[Pascal Error] Main.pas(179): E2250 There is no overloaded version of 'WriteFile' that can be called with these arguments

The SFTPClient demo compiles and works fine (at least the open function, write function is not used) in my environment.
I'm using BDS2006, SecureBridge 2.6.... and CrushFTP server.

Thanks for your help in advance
Heinz

Posted: Mon 20 Sep 2010 10:11
by Dimon
To solve the problem try to use the following code:

Code: Select all

  RemoteHandle:=ScSFTPClient1.OpenFile(ScSFTPClient1.RetrieveAbsolutePath('.')+remotefile,[ScSFTPUtils.FoCreate]);

Code: Select all

  ScSFTPClient1.WriteFile(RemoteHandle, Offset, Buffer[0], Count);

Worx!!!

Posted: Mon 20 Sep 2010 12:38
by EAC
Hi Dimon, I don't know where's the big difference but it works. Thanks !!! :D

Posted: Tue 21 Sep 2010 14:12
by Dimon
Feel free to contact us if you have any further questions about SecureBridge.