SymbolicLink Example
SymbolicLink Example
Does anyone have some example code for using OnReadSymbolicLink?
Re: SymbolicLink Example
To test you can use our SimpleSSHServer demo project. You can find the demo project in the %SecureBridgeDemos%\SimpleSSHServer directory. %SecureBridgeDemos% is the SecureBridge Demo projects installation path on your computer.
Then you can use the following code:
Note, please add the following modules in the USES clause of your module:
Then you can use the following code:
Code: Select all
procedure TSSHServerFrame.ScSFTPServerReadSymbolicLink(Sender: TObject;
SFTPSessionInfo: TScSFTPSessionInfo; const Path: string;
out SymbolicName: string; var Error: TScSFTPError);
var
FullPath: string;
{$IFDEF MSWINDOWS}
IObj: IUnknown;
ILink: IShellLink;
IPFile: IPersistFile;
fd: TWin32FindData;
ws: WideString;
pPath: PChar;
{$ENDIF}
begin
SymbolicName := '';
FullPath := ScSFTPServer.GetFullPath(SFTPSessionInfo, Path);
if not FileExists(FullPath) and (ExtractFileExt(FullPath) = '') then
FullPath := ChangeFileExt(FullPath, '.lnk');
{$IFDEF SC_USE_SYMLINK}
if FileGetSymLinkTarget(FullPath, SymbolicName) then
InitError(Error, erOk)
else
{$ENDIF}
{$IFDEF MSWINDOWS}
if FileExists(FullPath) then begin
InitError(Error, erFailure);
try
IObj := CreateComObject(CLSID_ShellLink);
ILink := IObj as IShellLink;
IPFile := IObj as IPersistFile;
ws := WideString(FullPath);
if IPFile.Load(POleStr(ws), 0) = S_OK then begin
pPath := Marshal.AllocHGlobal(MAX_PATH * sizeof(char));
try
if ILink.GetPath(pPath, MAX_PATH, fd, 0) = S_OK then begin
SymbolicName := string(pPath);
SymbolicName := ExtractRelativePath(SFTPSessionInfo.HomePath, SymbolicName);
InitError(Error, erOk);
Exit;
end;
finally
Marshal.FreeHGlobal(pPath);
end;
end;
finally
if Error.ErrorCode <> erOk then
InitError(Error, erFailure, SysErrorMessage(GetLastError));
end;
end
else
{$ENDIF}
InitError(Error, erNoSuchFile);
end;
Code: Select all
uses
{$IFDEF MSWINDOWS}
ShlObj, ActiveX, ComObj,
{$ENDIF}
ScSFTPUtils, ScSFTPConsts, ScCLRClasses,
Re: SymbolicLink Example
I was hoping this would help show how to create virtual mounts for the sftp server. I do not see it. Is there a way to configure the server to use virtual mount points?
Re: SymbolicLink Example
What do you mean by virtual mount points? We advise users on using the SFTP protocol, but not on working with a file system.
Re: SymbolicLink Example
The ability to add an additional home path for the remote user to access.
Re: SymbolicLink Example
You can use the TScUser.HomePath property to specify a user home path. If you're looking for something else, let us know.
Re: SymbolicLink Example
In addition to the homepath I would like to be able to add one or more virtual mounts points that would act like directories to the remote system but point to other network or local paths. I will look through the source but I have not found where it builds the directory listing yet.
Re: SymbolicLink Example
In the SFTP specification, there's no such concept as a directory or directory navigation. You should pass the full path whenever you write or read a file on the server. The TScSFTPServer.GetFullPath method receives the path from the client and returns the path that the operating system understands. You can parse and handle the path either in this method or in the OnGetFullPath handler. You can implement your own rules for specifying the path to virtual catalogs and parse the path using the GetFullPath method.
Re: SymbolicLink Example
Thank you for interest to our product.
Feel free to contact us if you have any further questions about our products.
Feel free to contact us if you have any further questions about our products.