Solved

FTP upload for filesonic

Posted on 2011-09-12
17
1,125 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 101

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 101

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month7 days, 17 hours left to enroll

617 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