Jump to content

UniGUI as FTP Server - possible?


elGringo
 Share

Recommended Posts

SeverModule has event for custom HTTP requests, so you can POST a file as octet stream from VCL app to your UNI app.

 

However I recommend to use cloud services like Amazon S3 for example. There are existing Delphi libs to manage cloud services and you'll get a working link when file is uploaded without cluttering your server.

Link to comment
Share on other sites

Zilav - thank you very much for the answer!!! I will try to do that for myself - but could your give a small example - an idea how to do that - if i will choose the 1 variant. One thing in that I write program that will be deployed on different VPS Windows Servers, so it must not depend on Amazon only.

 

Also, I have Azure account - maybe there's complete lib for that task too... - but it also means dependence on Azure only... So I'm in process...

Link to comment
Share on other sites

Zilav - thank you very much !!! I will post here my results anyway. And about clouds - i will test it too. Have a nice day there.

Here is an example from my project where I generate thubmnails and upload them to S3 with public access for internet shop.

function TFrameItems.UploadThumbnail(aStream: TStream; aName: string): Boolean;
var
  s3: TAmazonS3;
begin
  Result := False;
  s3 := TAmazonS3.Create(Self);
  try
    try
      s3.AccessKeyID := data.GetSetting('AWSAccessKeyId');
      s3.SecretAccessKeyID := data.GetSetting('AWSSecretKey');
      s3.AmzHeaders.Values['x-amz-acl'] := 'public-read';
      s3.AmzHeaders.Values['x-amz-storage-class'] := 'REDUCED_REDUNDANCY';
      s3.UploadObject(data.GetSetting('AWSBucketName'), aName, 'image/jpeg', aStream);
      Result := True;
    except
      // handle error here
    end;
  finally
    s3.Free;
  end;
end;

AmazonS3.zip

Link to comment
Share on other sites

And can this task decided with TidFTPServer and TidFTP?

Only if you run a single instance of UniGui app on the host machine (standalone or server). ISAPI won't work at all.

 

If you still insist on using FTP, then install any free FTP server. From your VCL app generate unique name for a file to upload (probably some hash), send it to FTP server with TIdFTP, then http POST uploaded unique file name to UniGUI app as I've shown you.

Link to comment
Share on other sites

My task quite simple - to put file (for example 123.jpg or 123.mp3 or 123.mp4) near UniServer from my vcl app and to get link - for example http://localhost:8077/123.jpg and to use it in vcl.

It is clear for me that with ftp i will put it

I need link in vcl app, so in that case http.post no needed?

 

Also you say interesting thing - i'm trying to understand

 

Only if you run a single instance of UniGui app on the host machine (standalone or server). ISAPI won't work at all.

 

In attachment - picture from http://www.unigui.com/explore/technology-overview

 

ISAPI Handler create MainModule which is creating DataModules and so on. So if to put IdFTPServer on MainModule for example - will it be multiplied to number of sessions? 

 

I ask because just want something embedded (some ftp server embedded or http server embedded) in my program to not to install hundered of additional programs.

 

post-2378-0-63942800-1472672339_thumb.jpg

Link to comment
Share on other sites

Yes, i also came to that decision. Sheme is following

 

to upload file from vcl app (Ftp Client) to ServerMachine

 

-Check FTPServer Is Started, in not than start FTPServer as EXE on ServerMachine

-send file from FTPClient

-receive approval that file is uploaded

..next steps

 

than next question - how remotely start EXE file on Server Machine from for example FTPClient? 

Link to comment
Share on other sites

Don't you know if I do like so

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
ShellExecute(Handle, 'open',
  'c:\Windows\notepad.exe', nil, nil, SW_SHOWNORMAL);
end; 

Do I start it on local client machine or on Server Machine? I will test it on my Azure today

Link to comment
Share on other sites

Ok. I tested

ErrorCode:=shellAPI.ShellExecute(Handle, 'open',
  PWideChar('c:\Windows\System32\notepad.exe'), nil, nil, SW_SHOWNORMAL);

this opens notepad on ServerSide - on my Azure Machine

 

So, using this approach - I can start FTP Server on my Azure and any other EXE

 

But how to start or stop remotely UniGUI.EXE Itself?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...