Recent

Author Topic: Synapse TFTP file transfer  (Read 11209 times)

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Synapse TFTP file transfer
« on: May 28, 2020, 09:27:01 am »
Hello!

I found the TTFTP in synapse but I read about it and I realized it isn't good for me...
So I changed to TFTP but it's harder  :( how can I use It?
Some Guide/tutorial anywhere?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Synapse TFTP file transfer
« Reply #1 on: May 28, 2020, 09:58:33 am »
The TFTP protocol (provided by the TTFTP class is indeed mainly intended for file transfers for boot protocols like PXE).

To download files using FTP (provided by the TFTP class) you can take a look here to get you started (I didn't test it myself though).

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #2 on: May 28, 2020, 11:24:00 am »
I found 3 procedure:

Quote
.DataStream(Tstream);
.DataWrite(Tstream);
.DataRead(Tstream);
how can I use them and send the streams?

Or I can use the file commands?
(storeFile,directFile,...)

Maybe ftpPutFile and ftpGetFile ?
« Last Edit: May 28, 2020, 11:30:42 am by Jake012345 »

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Synapse TFTP file transfer
« Reply #3 on: May 28, 2020, 12:44:20 pm »
Maybe ftpPutFile and ftpGetFile ?
Yes. Did you look at the link PascalDragon provided?
There is an example.

For further examples you can download synapse40.zip from http://synapse.ararat.cz/doku.php/download
In that zip there is a demo directory (in the source directory) which has many examples.
One of them is TFTPClient. Look at that one.

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #4 on: May 28, 2020, 01:17:37 pm »
Thats okay.

I think It's working like a real online server and I can upload and download the files with client program. Am I right?

But I want to write a program what can send directly the files for it's 'sibling' program.
Like a messenger, torrent, and the others.
Sure not complicated like them. Just simple. Most simple. What am I have to use and how?
Every example what I fount had a lot of extra what I don't need, and it's confusing me..  :'(

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Synapse TFTP file transfer
« Reply #5 on: May 28, 2020, 01:57:30 pm »
I think It's working like a real online server and I can upload and download the files with client program. Am I right?
Yes, you'll need an FTP server. But in the demo directory of Synapse there is also a TFTPServer example.
So you could add a FTPserver on both ends to do the filetransfer up and down (of if you only need it one way it's even easier).

Otherwise... you could use the TCP example from a few weeks ago.
That was for sending and receiving text-messages.
But you could implement something like:
if you receive @file:filename:size as text... the following data (until size bytes) is binary information for a file.
After that you'll need to ignore the received data as text until you receive the complete size-bytes of the file.

or
If mixing text and binary data is too hard you could also do something like
If you receive @file:filename:port... you connect the client to the port of the other side and all data received on that is for file with filename.

There is no standard for this. You'll need to implement it yourself.
But using a small ftp server and client is so much easier.
It's all implemented in one class (TTFTPSend), both server and client.
http://synapse.ararat.cz/doc/help/ftptsend.TTFTPSend.html

See the TFTCPClient and TFTPServer for an example.


fred

  • Full Member
  • ***
  • Posts: 201
Re: Synapse TFTP file transfer
« Reply #6 on: May 28, 2020, 02:00:17 pm »
Fot sending a file to a FTP server this is something I used years ago:
Code: Pascal  [Select][+][-]
  1. uses ftpsend;
  2.  
  3. procedure SendToFTP;
  4. var
  5.   FTP: TFTPSend;
  6.   ok: boolean;
  7. begin
  8.   ok := False;
  9.   FTP := TFTPSend.Create;
  10.   try
  11.     try
  12.       FTP.TargetHost := 'ftp.test.com';
  13.       FTP.UserName := 'test';
  14.       FTP.Password := 'test';
  15.  
  16.       if FTP.Login then begin
  17.         FTP.BinaryMode := true;
  18.         FTP.DirectFile := true;
  19.         FTP.DirectFileName := 'c:\test.zip';
  20.         if FTP.StoreFile('test.zip', false)
  21.         then ok := True;
  22.         FTP.Logout;
  23.       end;
  24.  
  25.       if not ok
  26.       then Log(FTP.ResultString);
  27.  
  28.     except
  29.       on E: Exception do begin
  30.         Log('Exception: '+E.Message);
  31.       end;
  32.     end;
  33.  
  34.   finally
  35.     FTP.Free;
  36. end;

I changed the original code to I hope I didn't change too much...

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #7 on: May 28, 2020, 06:18:16 pm »
 :D

Can I read and write the stream with ftpsend and send it with blocksock?  ;D

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Synapse TFTP file transfer
« Reply #8 on: May 28, 2020, 06:36:08 pm »
Can I read and write the stream with ftpsend and send it with blocksock?  ;D
No, why? You can use the the sendfile and recvfile for that.

You could stuff some data with blocksock on the wire but that will only mess things up.

Why would you want that?

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #9 on: May 28, 2020, 06:41:56 pm »
There is sendfile command?

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Synapse TFTP file transfer
« Reply #10 on: May 28, 2020, 06:51:59 pm »
There is sendfile command?
Didn't you look at the link I gave for TFTPSend???  >:D

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #11 on: May 29, 2020, 06:42:20 am »
Oh really but it's TFTP and that's UDP :(

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: Synapse TFTP file transfer
« Reply #12 on: May 29, 2020, 08:28:59 am »
Oh really but it's TFTP and that's UDP :(

I let the code speak fro itself :D

Code: Pascal  [Select][+][-]
  1. constructor TFTPSend.Create;
  2. begin
  3.   inherited Create;
  4.   FFullResult := TStringList.Create;
  5.   FDataStream := TMemoryStream.Create;
  6.   FSock := TTCPBlockSocket.Create;      {$LOOK a TCPBlockSocket}
  7.   FSock.Owner := self;
  8.   FSock.ConvertLineEnd := True;
  9.   FDSock := TTCPBlockSocket.Create; {$LOOK a TCPBlockSocket}
  10.   FDSock.Owner := self;
  11.   FFtpList := TFTPList.Create;
  12.   FTimeout := 300000;
  13.   FTargetPort := cFtpProtocol;
  14.   FUsername := 'anonymous';
  15.   FPassword := 'anonymous@' + FSock.LocalName;
  16.   FDirectFile := False;
  17.   FPassiveMode := True;
  18.   FForceDefaultPort := False;
  19.   FForceOldPort := false;
  20.   FAccount := '';
  21.   FFWHost := '';
  22.   FFWPort := cFtpProtocol;
  23.   FFWUsername := '';
  24.   FFWPassword := '';
  25.   FFWMode := 0;
  26.   FBinaryMode := True;
  27.   FAutoTLS := False;
  28.   FFullSSL := False;
  29.   FIsTLS := False;
  30.   FIsDataTLS := False;
  31.   FTLSonData := True;
  32. end;
  33.  

class TTFTPSend <> class TFTPSend

But that doesn't seem to matter anyhows, as your end-goal seems something completely different then as stated here in this thread.

But I want to write a program what can send directly the files for it's 'sibling' program.
Like a messenger, torrent, and the others.
Sure not complicated like them. Just simple. Most simple. What am I have to use and how?
Every example what I fount had a lot of extra what I don't need, and it's confusing me..  :'(
All what you call extra is required to get a healthy synced communication going between server and client (*) (as was explained in an earlier thread, to which you did not reply and the advise was ignored so that you started yet another thread on the same subject, doing so repeatedly).

(*) how _you_ wish to implement that (communication) is _your_ business. You would have to invent that for your custom purpose, and for that you need to have a clear picture of what you want with your client'/server model, and you can't simply play around with this topic gluing stand-alone examples together in the hopes that doing so will somehow work for your situation.

In case there is a language barrier then please write things down in your native tongue, and post that together with the google translation. Right now it is starting to look like you are bashing your head against the proverbial wall over and over again.

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #13 on: May 29, 2020, 09:27:23 am »
Szeretnék írni egy programot ami szöveges üzeneteket és file-okat is képes küldeni, a program másik példányának. És lehetőleg a host képes legyen több klienst is kiszolgálni. Nem igazán érdekel hogy ez milyen kapcsolattal jön létre, de a nagyobb fájlok küldéséhet szükséges a TCP kapcsolat.

I would like to write a program that can send text messages and files to another copy of the program. And preferably the host should be able to serve multiple clients. I don't really care what kind of connection this creates, but larger files may require a TCP connection.

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: Synapse TFTP file transfer
« Reply #14 on: May 29, 2020, 10:03:00 am »
@Jake012345
There you go (and thank you), that is much more precise and better to understand for the reader :)

Quote
I would like to write a program that can send text messages and files to another copy of the program.
You wish to use _different_ methods of sending data.

Quote
And preferably the host should be able to serve multiple clients.
You wish to a) supply multiple sockets (clients) all at once and/or b) one socket (client) after the other.

Depending on what you want things can get complicated because option a would require to implement threads while option b could do without using threads.

Quote
I don't really care what kind of connection this creates, but larger files may require a TCP connection.
The examples used in the earlier threads assumed TCPBlockSocket connections (TCP).

But as written in the other thread: it is perfectly ok to switch from sending strings to sending raw data (read: streams) and back again, over the same socket but_ you_ would have to come up with a communication protocol. I even provided an example on how such communication protocol (in theory) _could_ look like.

That is why there exists ready made (communication) protocols such as FTP, TFTP, HTML HTTP etc. These protocols where once made up and the RFC's determine how these clients and servers need to "talk" (communicate) to each other. That "talking" between client and servers is also known as (communication)-protocol.

You would have to invent your own communication protocol in order to make things work exactly the way how you want it to work, just as any other existing protocols (FTP/TFPT/HTMLHTTP/etc) do. There is not an example in the world that is able to teach that for you. You can always have a look at already existing protocols (RFC's/code) and read how they implemented their communications, but i doubt they would be helpful for your specific situation (as you stated earlier that the extra's in the code seem to confuse you).

edit: corrected html to read http, i was thinking http but wrote html  :-[
« Last Edit: May 29, 2020, 10:33:28 am by TRon »

 

TinyPortal © 2005-2018