Solved

FTP upload for filesonic

Posted on 2011-09-12
17
1,093 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now