Folder not found

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
Mike.Rewnick
Posts: 8
Joined: Sat 11 Dec 2010 23:07

Folder not found

Post by Mike.Rewnick » Tue 08 Feb 2011 22:09

Using SFTP server developed by this company

http://www.ipswitch.com

Trying to download the file using demo project

I am getting the error

SFTP server error occurred: Folder not found: d:\test\test\etl_test.txt.

looks like t is failing while trying to determine the file size.

RetrieveAttributesByHandle

But I can view the file in demo project

Mike

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Fri 11 Feb 2011 09:16

Please try using the following code to download the file and check if the problem still exists.

Code: Select all

procedure TForm1.DownloadFile(const SourceFileName, DestinationFileName: string);
var
  Handle: TScSFTPFileHandle;
  Hndl: THandle;
  Attrs: TScSFTPFileAttributes;
  Stream: THandleStream;
  Buf: TBytes;
  FileBlockSize: Integer;
  ReceivedCount: Integer;
  FileOffset: Int64;
begin
  ScSFTPClient.Initialize;
  Handle := ScSFTPClient.OpenFile(SourceFileName, [foRead], nil);
  try
    Stream := nil;
    Attrs := TScSFTPFileAttributes.Create;
    try
      ScSFTPClient.RetrieveAttributesByHandle(Attrs, Handle);
      FileBlockSize := ScSFTPClient.ReadBlockSize;
      if aSize in Attrs.ValidAttributes then
        if Attrs.Size < FileBlockSize then
          FileBlockSize := Attrs.Size;

      Hndl := CreateFile(DestinationFileName, GENERIC_READ or GENERIC_WRITE, 0,
        nil, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
      Stream := THandleStream.Create(Hndl);

      SetLength(Buf, FileBlockSize);
      FileOffset := 0;
      repeat
        ReceivedCount := ScSFTPClient.ReadFile(Handle, FileOffset, Buf, 0, FileBlockSize);
        Stream.WriteBuffer(Buf[0], ReceivedCount);
        FileOffset := FileOffset + ReceivedCount;
      until ScSFTPClient.EOF;

    finally
      FileClose(Stream.Handle);
      Attrs.Free;
    end;
  finally
    ScSFTPClient.CloseHandle(Handle);
  end;
end;

hdokit
Posts: 4
Joined: Fri 18 Dec 2015 10:50

Re: Folder not found

Post by hdokit » Fri 18 Dec 2015 13:19

I have the same problem, apparently. I tried your suggested code, but this fails at the RetrieveAttributesByHandle, just like Mike originally reported.

hdokit
Posts: 4
Joined: Fri 18 Dec 2015 10:50

Re: Folder not found

Post by hdokit » Fri 18 Dec 2015 14:03

Using "RetrieveAttributes" instead of "RetrieveAttributesByHandle" works, interestingly.

However, I still cannot download a file, I get 3 chunks, and at the 4th loop iteration I always get an "Connection timeout expired" message. I tried increasing Timeout, but that didn't help. Any ideas?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Folder not found

Post by ViktorV » Thu 14 Jan 2016 14:57

Unfortunately, we couldn't reproduce the issue on our SFTPClient demo project. For the issue investigation, if it is possible, please give us test access to your server. Otherwise, specify the used versions of the OS and SFTP server.

Post Reply