Recent

Author Topic: [SOLVED] Synapse - How to simply make a file upload?  (Read 19974 times)

lazguy

  • Jr. Member
  • **
  • Posts: 78
[SOLVED] Synapse - How to simply make a file upload?
« on: October 07, 2011, 07:36:01 pm »
Hallo Everybody !!!!!!!!!!!!!

I am using the following procedure to download a file:

Code: [Select]
procedure DownloadFile(const Url, PathToSaveTo: string);
begin
   fs := TFileStream.Create(PathToSaveTo, fmOpenWrite or fmCreate);
   try
      HttpGetBinary(Url, fs);
   finally
      fs.Free;
   end;
end;


How to do the same to upload a file (maybe FTP ? username and password ? or HTTP ? or other way ?) Please, write the code like the one above.

Thank you very much in advance !!!!
« Last Edit: February 08, 2012, 02:39:43 am by lazguy »

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: Synapse - How to simply make a file upload?
« Reply #1 on: October 07, 2011, 09:25:54 pm »
This is a function I use for FTP upload.  I had to strip quite a few things not relevant for you, so I hope I haven't broken anything.  You should add some displaying here and there, but this was the core ...

Code: [Select]
function TModel.Send(LocalFile : string; remoteFile : string; RemoteDir : string) : boolean;
//===========================================================================
//     **********************************************************************
//     * Send a file to the FTP server                                      *
//     **********************************************************************
//---------------------------------------------------------------------------
var
   rc : boolean;
begin
   // Create the FTP Client object and set the FTP parameters
   FTPClient := TFTPSend.Create;
   with FTPClient do begin
      TargetPort  := cFtpProtocol;
      TargetHost := fHost;  // these were properties set somewhere else
      UserName := fUserID;
      Password := fPassword;
      //-----------------------------------------------------------------------
      // bail out if the FTP connect fails
      if not LogIn then exit;
      //------------------------------------------------------------------------

      // Set filename to FTP
      DirectFileName := LocalFile;
      DirectFile := True;
      //------------------------------------------------------------------------

      // change directory if requested
      if RemoteDir <> '' then ChangeWorkingDir(RemoteDir);
      //------------------------------------------------------------------------

      // STOR file to FTP server. 
      rc := StoreFile(RemoteFile,false);
      //------------------------------------------------------------------------

      // close the connection
      LogOut;
      //------------------------------------------------------------------------
      // free the FTP client object
      free;
      //------------------------------------------------------------------------
   end;
   Result := rc;
//===========================================================================
end;
« Last Edit: October 07, 2011, 09:32:36 pm by Arbee »
1.0/2.6.0  XP SP3 & OS X 10.6.8

lazguy

  • Jr. Member
  • **
  • Posts: 78
Re: Synapse - How to simply make a file upload?
« Reply #2 on: October 13, 2011, 02:30:03 am »
Thank You Very, Very Much, Arbee !!!!!!

Perfect !!!!!!!

Solved.

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
Uses?
« Reply #3 on: July 18, 2016, 11:44:15 am »
This is a function I use for FTP upload.  I had to strip quite a few things not relevant for you, so I hope I haven't broken anything.  You should add some displaying here and there, but this was the core ...

Code: [Select]
function TModel.Send(LocalFile : string; remoteFile : string; RemoteDir : string) : boolean;
//===========================================================================
//     **********************************************************************
//     * Send a file to the FTP server                                      *
//     **********************************************************************
//---------------------------------------------------------------------------
var
   rc : boolean;
begin
   // Create the FTP Client object and set the FTP parameters
   FTPClient := TFTPSend.Create;
   with FTPClient do begin
      TargetPort  := cFtpProtocol;
      TargetHost := fHost;  // these were properties set somewhere else
      UserName := fUserID;
      Password := fPassword;
      //-----------------------------------------------------------------------
      // bail out if the FTP connect fails
      if not LogIn then exit;
      //------------------------------------------------------------------------

      // Set filename to FTP
      DirectFileName := LocalFile;
      DirectFile := True;
      //------------------------------------------------------------------------

      // change directory if requested
      if RemoteDir <> '' then ChangeWorkingDir(RemoteDir);
      //------------------------------------------------------------------------

      // STOR file to FTP server. 
      rc := StoreFile(RemoteFile,false);
      //------------------------------------------------------------------------

      // close the connection
      LogOut;
      //------------------------------------------------------------------------
      // free the FTP client object
      free;
      //------------------------------------------------------------------------
   end;
   Result := rc;
//===========================================================================
end;
Uses???
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: Uses?
« Reply #4 on: July 18, 2016, 12:05:06 pm »
Uses???
ftptsend.

Download the library at http://www.ararat.cz/synapse/doku.php/download
(specifically the SVN version. Click the download snapshot button at https://sourceforge.net/p/synalist/code/HEAD/tree/trunk/)

Open your project.
Choose Package > Open Package File and choose laz_synapse.lpk and Compile and Use > Add to project.
Now include ftpsend to your uses clause in the unit you have this snippet in.

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
Re: Uses?
« Reply #5 on: July 18, 2016, 12:22:07 pm »
Uses???
ftptsend.

Download the library at http://www.ararat.cz/synapse/doku.php/download
(specifically the SVN version. Click the download snapshot button at https://sourceforge.net/p/synalist/code/HEAD/tree/trunk/)

Open your project.
Choose Package > Open Package File and choose laz_synapse.lpk and Compile and Use > Add to project.
Now include ftpsend to your uses clause in the unit you have this snippet in.
Can i use this unit on Free Pascal? And if yes where i can find a tutorial for installation? Because i tried with other units but installing always gives error
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: Uses?
« Reply #6 on: July 18, 2016, 12:24:51 pm »
Can i use this unit on Free Pascal? And if yes where i can find a tutorial for installation? Because i tried with other units but installing always gives error
You don't need to "install" this library. You can just "use" it. (there is also no "install" option under "Use" in Lazarus. only "Add to project".)

And yes, you can use it in Free Pascal. In that case you just need to add the path to the library source files and include the ftpsend in the uses. FPC will find it and compile all necessary files.

What errors are you getting.

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
Re: [SOLVED] Synapse - How to simply make a file upload?
« Reply #7 on: July 18, 2016, 01:06:29 pm »
Oh ok  so this unit is simply to add.. I tried to install ZenGL graphics but it tells that there are errors in the syntax of the demo code for free pascal.. But now it doesn't matter. I should add ftpsend and see if it works
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

 

TinyPortal © 2005-2018