Solved

FTP upload for filesonic

Posted on 2011-09-12
17
1,114 Views
Last Modified: 2012-05-12
I am very much interested for FTP upload for filesonic file hosting.

Want to add a button which browse any kind of file
and upload. Also I progress bar needed to see complete uploads. After complete upload I also see download link like http://filesonic.com/files/5445454/myfreewareapp.zip

I check this page for API for not clear to me.

Filesonic API:
http://api.filesonic.com/docs

Any one can guide me with code?

Thanks in advance.
0
Comment
Question by:prasiddutta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
17 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 36527848
Try this code...

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,WinINet;

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    lbServer: TLabel;
    edServer: TEdit;
    lbServerHint: TLabel;
    edUsername: TEdit;
    lbUsername: TLabel;
    edPassword: TEdit;
    lbPassword: TLabel;
    edRemoteFolder: TEdit;
    lbRemoteFolderHint: TLabel;
    lbRemoteFolder: TLabel;
    edPort: TEdit;
    lbPortHint: TLabel;
    lbPort: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function FtpUploadFile(ToServer, username, password, LocalFile, RemoteFile: string; port: word = 21): boolean;
var
  hIOpen, hIConnect: HINTERNET;
begin
  hIOpen := InternetOpen('myagent', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);
  hIConnect := InternetConnect(hIOpen, pchar(ToServer), port, pchar(username), pchar(password), INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
  Result := FtpPutFile(hIConnect, pchar(localfile), pchar(remotefile), FTP_TRANSFER_TYPE_UNKNOWN, 0);
  InternetCloseHandle(hIConnect);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  RemoteFileName:string;
begin
  if OpenDialog1.Execute then begin
    RemoteFileName:=edRemoteFolder.Text+ExtractFileName(OpenDialog1.FileName);
    if FtpUploadFile(edServer.Text,edUsername.Text,edPassword.Text,OpenDialog1.FileName,RemoteFileName,StrToInt(edPort.Text)) then
      MessageDlg('Upload OK!!!',mtInformation,[mbOK],0)
    else
      MessageDlg('Upload Error!!!',mtError,[mbOK],0);
  end;
end;

end.

Open in new window

IDE-MainForm-Screenshot.JPG
0
 
LVL 19

Expert Comment

by:Thommy
ID: 36527969
Here is the complete Delphi XE project...
FtpUpload.zip
0
 

Author Comment

by:prasiddutta
ID: 36528086
Quite well and thanks for respond. I need a progress bar and want to get download link too.

Sir, did you check http://api.filesonic.com/docs

How retrive download links?

Thanks.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 100

Expert Comment

by:mlmcc
ID: 36958282
I've requested that this question be closed as follows:

Accepted answer: 500 points for Thommy's comment http:/Q_27304016.html#36527969

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 

Author Comment

by:prasiddutta
ID: 36940628
@mlmcc

Thommy donr provide correct answer. I think someone will help me regarding JSON with Delphi.
0
 
LVL 19

Expert Comment

by:Thommy
ID: 36960899
Example how to use the filesonic API with TIdHTTP.Get...

Don't forget to initialize http.ProxyParams!!!
procedure TForm1.GetFileSonicDomains;
var
  HTTP: TIdHTTP;
begin
  HTTP := TIdHttp.Create(nil);

  try
    with HTTP do begin
      http.ProxyParams.ProxyPort:=...;
      http.ProxyParams.ProxyServer:='...';
      http.ProxyParams.ProxyUsername:='...';
      http.ProxyParams.ProxyPassword:='...';
      http.ProxyParams.BasicAuthentication:=true;

      HandleRedirects := true;
      Request.ContentLength := -1;
      Request.Accept := 'text/html, */*';
      HTTPOptions := [hoForceEncodeParams];
    end;
    Memo1.Text:=HTTP.Get('http://api.filesonic.com/utility?method=getAllFileSonicDomains');

  except
    on e: Exception do ShowMessage('XXX'+#10+E.Message);
  end;
end;

Open in new window

0
 
LVL 19

Accepted Solution

by:
Thommy earned 500 total points
ID: 36960915
You can also directly load the response content into a stream and return it as a string result of the calling function...
function GetURLAsString(aURL: string): string;
var   HTTP: TIdHTTP;
      lStream: TStringStream;
begin
  HTTP := TIdHTTP.Create(nil);
  http.ProxyParams.ProxyPort:=8080;
  http.ProxyParams.ProxyServer:='demulsgw0002.ebmpapst.net';
  http.ProxyParams.ProxyUsername:='dvbetzth';
  http.ProxyParams.ProxyPassword:='12345';
  http.ProxyParams.BasicAuthentication:=true;

  lStream := TStringStream.Create(Result);
  try
    HTTP.Get(aURL, lStream);
    lStream.Position := 0;
    Result := lStream.ReadString(lStream.Size);
  finally
    FreeAndNil(HTTP);
    FreeAndNil(lStream);
  end;
end;


Memo1.Text:=GetURLAsString('http://api.filesonic.com/utility?method=getAllFileSonicDomains');

Open in new window

0
 
LVL 19

Expert Comment

by:Thommy
ID: 36960930
For handling the responses in JSON data format please refer to JSON delphi library project at sourceforge.net:

http://lkjson.sourceforge.net/
0
 

Author Comment

by:prasiddutta
ID: 36961239
@Thommy

Honestly I don’t understand. Can you elaborate this?

Step by step? Thank you.
0
 
LVL 19

Expert Comment

by:Thommy
ID: 36961743
Have provided all relevant information.

Seems that you are not much experienced in Delphi programming and HTTP Post and Get methods!

Do you have problems implementing my posted code or have you already managed to verify it???

With http.Get method you can pass over the filesonic API calls (http://api.filesonic.com/docs) as shown in my code examples
with FSApi_Utility / getAllFileSonicDomains.

In my examples I have stored the response into a memo field:

You can analyze the response data and retrieve information.

If you want your response data in XML or JSON format, you have to pass a format parameter with the FSAPI call.

So for example with FSApi_Utility / getAllFileSonicDomains you have to adapt your FSAPI call as follows:

XML Data format Response:
http://api.filesonic.com/utility?method=getAllFileSonicDomains&format=xml

JSON Data format Response
http://api.filesonic.com/utility?method=getAllFileSonicDomains&format=JSON

If your preferred data format is JSON, the JSON Delphi library project at http://lkjson.sourceforge.net/ will help you to handle JSON data format...





0
 

Author Comment

by:prasiddutta
ID: 36961774
Thanks. I add uLkJSON in my project.

>> Seems that you are not much experienced in Delphi programming and HTTP Post and Get methods!

Really NOT.

If you make a simple or example project like this then it'll more helpful for me.

Thanks a lot.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 37123597
I've requested that this question be deleted for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 

Author Comment

by:prasiddutta
ID: 37123594
Now I agree to give point. Project is partially completed.
0
 

Author Comment

by:prasiddutta
ID: 37123598
Thanks.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question