Solved

FTP upload for filesonic

Posted on 2011-09-12
17
1,102 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

803 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