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 change the color f...
by
Thaddy
[
Today
at 06:01:15 pm]
Dynarray initialization p...
by
Martok
[
Today
at 05:39:03 pm]
Project fails on run but ...
by
dseligo
[
Today
at 05:30:42 pm]
JEDI error but unit compi...
by
bobonwhidbey
[
Today
at 05:03:48 pm]
Zeos components. Had to c...
by
Fantablup
[
Today
at 04:17:13 pm]
[SOLVED] Completion box s...
by
furious programming
[
Today
at 04:12:26 pm]
[LAMW] How to create a ca...
by
af0815
[
Today
at 03:48:16 pm]
Complex package installat...
by
wp
[
Today
at 03:38:16 pm]
A "leisure" question on W...
by
gidesa
[
Today
at 03:17:10 pm]
Curling Pythagoras Tree: ...
by
AlexTP
[
Today
at 03:07:53 pm]
[SOLVED] Combined pointer...
by
CM630
[
Today
at 02:48:41 pm]
Controlling the behavior ...
by
rvk
[
Today
at 02:35:41 pm]
Using KeyPress event, how...
by
Zvoni
[
Today
at 02:24:42 pm]
a Unit problem?
by
Thaddy
[
Today
at 01:56:12 pm]
Understanding and adjusti...
by
ArchChem
[
Today
at 12:58:12 pm]
Any upgrades to fpWeb pag...
by
marcov
[
Today
at 12:50:25 pm]
Help needed with Cairo / ...
by
Roland57
[
Today
at 12:25:16 pm]
Configure JCF messages
by
DomingoGP
[
Today
at 11:26:55 am]
IDE instability on Raspbe...
by
rvk
[
Today
at 10:37:14 am]
Boleeman's projects are p...
by
AlexTP
[
Today
at 10:18:04 am]
Your best UI design - con...
by
circular
[
Today
at 09:36:11 am]
ZeosDBO and querys using ...
by
Zvoni
[
Today
at 09:27:17 am]
STARS with line border st...
by
Boleeman
[
Today
at 09:13:29 am]
A button require administ...
by
Fibonacci
[
Today
at 05:57:21 am]
How to detect one externa...
by
d2010
[
Today
at 12:24:32 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: (SOLVED) FTP download in memory (Read 5447 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: 6111
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: 6111
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: 6111
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