Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Networking and Web Programming
»
(SOLVED) FTP download in memory
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
IRC channel
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
how to tweek fpmake to co...
by
paule32
[
Today
at 08:23:49 am]
splitting an image
by
paule32
[
Today
at 08:20:33 am]
Why isn't TTIRadioGroup's...
by
egsuh
[
Today
at 08:09:35 am]
FpDebug questions
by
440bx
[
Today
at 03:43:41 am]
Lazarus for Windows on aa...
by
Wallaby
[April 23, 2024, 11:46:56 pm]
Parameter passing odditie...
by
KodeZwerg
[April 23, 2024, 11:04:39 pm]
Can function be used for ...
by
jamie
[April 23, 2024, 10:53:10 pm]
(Solved) TIndexedAVLTree ...
by
lainz
[April 23, 2024, 10:49:03 pm]
Demo Scene Picture sinwav...
by
KodeZwerg
[April 23, 2024, 10:26:21 pm]
fkInternalCalc
by
zraja
[April 23, 2024, 09:31:07 pm]
A fairly simple sound sol...
by
KodeZwerg
[April 23, 2024, 09:23:37 pm]
add new targets to make
by
marcov
[April 23, 2024, 08:38:42 pm]
Quirky windows
by
ASerge
[April 23, 2024, 07:07:16 pm]
[Request] Demo Scene Sub ...
by
Gigatron
[April 23, 2024, 06:29:39 pm]
Unlocking Files
by
KodeZwerg
[April 23, 2024, 06:03:08 pm]
[SOLVED] trunk bug for mi...
by
Key-Real
[April 23, 2024, 05:56:32 pm]
Demo Scene Bitmap Font Sc...
by
Gigatron
[April 23, 2024, 05:56:27 pm]
Compile/Convert Delphi pr...
by
Martin_fr
[April 23, 2024, 05:43:11 pm]
Generics - correct syntax
by
Thaddy
[April 23, 2024, 05:40:59 pm]
InstallAware Using Lazaru...
by
msintle
[April 23, 2024, 05:26:36 pm]
Xcode Command Line Tools ...
by
Joseph
[April 23, 2024, 05:16:39 pm]
Offical launch of the 1 B...
by
Hartmut
[April 23, 2024, 04:49:29 pm]
what to do if my target M...
by
nickysn
[April 23, 2024, 04:16:02 pm]
compiler error in unit
by
paule32
[April 23, 2024, 03:49:50 pm]
Multithreading - synchron...
by
mika
[April 23, 2024, 01:48:51 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: (SOLVED) FTP download in memory (Read 5486 times)
xinyiman
Hero Member
Posts: 2256
(SOLVED) FTP download in memory
«
on:
June 06, 2016, 11:39:38 am »
Hello guys, does anyone have an example of an FTP download with synapse but that does not create the file but rather charge me the downloaded image directly into a TPicture? In short working only in RAM to be faster. Thank you
«
Last Edit: June 07, 2016, 01:04:31 pm by xinyiman
»
Logged
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1
balazsszekely
Guest
Re: FTP download in memory
«
Reply #1 on:
June 06, 2016, 12:11:45 pm »
With Indy you can. There is an overloaded version of IdFTP.Get method which accepts as parameter a stream:
Code: Pascal
[Select]
[+]
[-]
procedure
Get
(
const
ASourceFile
:
string
;
ADest
:
TStream
;
AResume
:
Boolean
=
false
)
;
overload
;
Looking at the synapse code, I see the FtpGetFile function, which internally use the RetriveFile then the DataRead method. DataRead accepts a stream parameter, so in theory it's possible but you have to do a little work.
Logged
rvk
Hero Member
Posts: 6169
Re: FTP download in memory
«
Reply #2 on:
June 06, 2016, 12:15:15 pm »
Just set DirectFile to false. It will use the FDataStream (TMemoryStream) to read the file in memory.
You'll have to do something like this:
Code: Pascal
[Select]
[+]
[-]
uses
ftpsend
;
function
ReadFtpToImage
(
const
IP
,
Port
,
FileName
,
User
,
Pass
:
string
;
Image1
:
TImage
)
:
boolean
;
begin
Result
:
=
False
;
with
TFTPSend
.
Create
do
try
if
User <>
''
then
begin
Username
:
=
User
;
Password
:
=
Pass
;
end
;
TargetHost
:
=
IP
;
TargetPort
:
=
Port
;
if
not
Login
then
Exit
;
DirectFileName
:
=
'dummyfilename'
;
DirectFile
:
=
False
;
// <------ Important !!
Result
:
=
RetrieveFile
(
FileName
,
False
)
;
if
Result
then
Image1
.
Picture
.
LoadFromStream
(
DataStream
)
;
Logout
;
finally
Free
;
end
;
end
;
Logged
xinyiman
Hero Member
Posts: 2256
Re: FTP download in memory
«
Reply #3 on:
June 07, 2016, 08:39:21 am »
Ok rvk, it works great , and if I wanted to do it reverse ? That is, send to FTP the contents of a TImage component ?
Logged
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1
rvk
Hero Member
Posts: 6169
Re: FTP download in memory
«
Reply #4 on:
June 07, 2016, 10:12:01 am »
I've taken the source of FtpGetFile() to create the ReadFtpToImage.
So for the reverse you could have taken the FtpPutFile() and done the same.
Here is a (non-tested) example:
Code: Pascal
[Select]
[+]
[-]
uses
ftpsend
;
// source taken from FtpPutFile()
function
WriteImageToFtp
(
const
IP
,
Port
,
FileName
,
User
,
Pass
:
string
;
Image1
:
TImage
)
:
boolean
;
begin
Result
:
=
False
;
with
TFTPSend
.
Create
do
try
if
User <>
''
then
begin
Username
:
=
User
;
Password
:
=
Pass
;
end
;
TargetHost
:
=
IP
;
TargetPort
:
=
Port
;
if
not
Login
then
Exit
;
DirectFileName
:
=
'dummyfilename'
;
DirectFile
:
=
False
;
// <------ Important !!
Image1
.
Picture
.
SaveToStream
(
DataStream
)
;
// <-- this saves the image to ftp-stream
Result
:
=
StoreFile
(
FileName
,
False
)
;
// and transfers it to Filename on ftp server
Logout
;
finally
Free
;
end
;
end
;
Logged
xinyiman
Hero Member
Posts: 2256
Re: FTP download in memory
«
Reply #5 on:
June 07, 2016, 11:20:41 am »
But with the ' last example I refer to the file What ftp server resides on HD , I want to pass the content of image , then RAM to FTP
Logged
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1
rvk
Hero Member
Posts: 6169
Re: FTP download in memory
«
Reply #6 on:
June 07, 2016, 11:23:39 am »
Yes, that's what the WriteImageToFtp() I showed you does. It does the reverse from the previous ReadFtpToImage().
You supply WriteImageToFtp with a filename to store on the FTP side and the TImage with content. It will take the content of that TImage and store it on the FTP-side in Filename.
Logged
xinyiman
Hero Member
Posts: 2256
Re: FTP download in memory
«
Reply #7 on:
June 07, 2016, 01:04:17 pm »
You're right , it works well . thank you so much
Logged
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Networking and Web Programming
»
(SOLVED) FTP download in memory
TinyPortal
© 2005-2018