Page 1 of 1

Folder not found

Posted: Tue 08 Feb 2011 22:09
by Mike.Rewnick
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

Posted: Fri 11 Feb 2011 09:16
by Dimon
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;

Re: Folder not found

Posted: Fri 18 Dec 2015 13:19
by hdokit
I have the same problem, apparently. I tried your suggested code, but this fails at the RetrieveAttributesByHandle, just like Mike originally reported.

Re: Folder not found

Posted: Fri 18 Dec 2015 14:03
by hdokit
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?

Re: Folder not found

Posted: Thu 14 Jan 2016 14:57
by ViktorV
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.