Recent

Author Topic: Synapse Simple TFTPserver ReadOnly mode  (Read 6567 times)

SlowCoder

  • New member
  • *
  • Posts: 8
Synapse Simple TFTPserver ReadOnly mode
« on: April 09, 2011, 12:46:29 pm »
Hi all,

Recently discovered the Lazarus project, very good work !  :D

I try to make the Synapse TFTP-server example to work in readonly mode, to disable uploads to the server.

Probably I don't have enough understanding of the protocol, the following modification to TFTPDaemonThread does work but:

- The client does not receive the proper error on upload (it receives error 0, not error 2 (access violation))
   This is also the case with error 6 (File already exists), the client shows error 0, but this is original code.

- For a RRQ the server error 1 (File not found) is properly displayed in the client.

So, how can I get the appropriate error message send to/displayed in the client?

Code: [Select]
procedure TTFTPDaemonThread.Execute;
var RequestType:Word;
    FileName:String;
begin
  TFTPDaemon := TTFTPSend.Create;
  FLogMessage := 'ServerThread created on Port ' + FPort;
  Synchronize(UpdateLog);
  TFTPDaemon.TargetHost := FIPAdress;
  TFTPDaemon.TargetPort := FPort;
  try
    while not terminated do
      begin
        if TFTPDaemon.WaitForRequest(RequestType,FileName)
          then
            begin
              // Fill the Log-Memo whith Infos about the request
              case RequestType of
                1:FLogMessage := 'Read-Request from '
                                 + TFTPDaemon.RequestIP + ':' + TFTPDaemon.RequestPort;
                2:FLogMessage := 'Write-Request from '
                                 + TFTPDaemon.RequestIP + ':' + TFTPDaemon.RequestPort;
              end;
              Synchronize(UpdateLog);
              FLogMessage := 'File: ' + Filename;
              Synchronize(UpdateLog);

              // Process the Request
              case RequestType of
                1:begin  // Read request (RRQ)
                    if FileExists(MainForm.PathEdit.Text + FileName) { *Converted from FileExists*  }
                      then
                        begin
                          TFTPDaemon.Data.LoadFromFile(MainForm.PathEdit.Text + FileName);
                          if TFTPDaemon.ReplySend
                            then
                              begin
                                FLogMessage := '"' + MainForm.PathEdit.Text + FileName + '" successfully sent.';
                                Synchronize(UpdateLog);
                              end;
                        end
                      else TFTPDaemon.ReplyError(1,'File not Found');
                  end;
                2:begin  // Write request (WRQ)
{ my addition }if not FReadOnly then begin
                      if not FileExists(MainForm.PathEdit.Text + FileName) { *Converted from FileExists*  }
                        then
                          begin
                            if TFTPDaemon.ReplyRecv
                              then
                                begin
                                  TFTPDaemon.Data.SaveToFile(MainForm.PathEdit.Text + FileName);
                                  FLogMessage := 'File successfully stored to ' + MainForm.PathEdit.Text + FileName;
                                  Synchronize(UpdateLog);
                                end;
                          end
                        else TFTPDaemon.ReplyError(6,'File already exists');
                    end
{ my addition }else begin
{ my addition }  TFTPDaemon.ReplyError(2,'Access violation');
{ my addition }  FLogMessage := 'Access violation message send';
{ my addition }  Synchronize(UpdateLog);
{ my addition }end;
                    end;
                  end;
                end;
              end;
      end;
  finally
    TFTPDaemon.Free;
  end;
end;                 

ik

  • Jr. Member
  • **
  • Posts: 88
  • ik
    • LINESIP
Re: Synapse Simple TFTPserver ReadOnly mode
« Reply #1 on: April 09, 2011, 08:46:18 pm »
You have two different protocols:

1. FTP
2. TFTP

FTP = File Transfer Protocol
TFTP = Trivial File Transfer Protocol

FTP uses TCP to communicate, while TFTP works in the raw socket realm. It is used in the broadcast level, where DHCP and PXE are working, and it's the way that the PXE and other protocols are sent. There should be no ports at all for it afaik.

So you should not use TTFTP but TFTP if I understand your needs properly.

SlowCoder

  • New member
  • *
  • Posts: 8
Re: Synapse Simple TFTPserver ReadOnly mode
« Reply #2 on: April 10, 2011, 09:08:45 am »
Hi ik,

Thanks for your reply.

I want to use the TFTP-server for loading configuration and firmware to networkdevices.

Synapse has a demo TFTP-server and -client which I am using.

I thought my code above was the problem, but it is also in the original demo-code when sending a file to the server.

When I want to send a file to the server that exists, the client does not get errormessage 6 'File already exists', but 0 ''.
Using wireshark I can see the server sending the correct error code to the client, but the client appartently does not receive it properly, and display a 0 error.

When I want to receive a file, and it does not exist, the client displays the proper errormessage 1 'File not found'. Here error handling is OK.

To compile the TFTP demo's I had to change FileExistsUTF8 to FileExists in TTFTPDaemonThread. Could this be a problem?

How does client receive the error, I cant see this clearly, does ftptsend.pas handle it?



Using Laz 0.9.30 fpc 2.4.2 on XP

Edit: typo.
« Last Edit: April 10, 2011, 09:28:52 am by SlowCoder »

 

TinyPortal © 2005-2018