Author Topic: OPEN SOCKET FROM PLC TO a FTP server.  (Read 5800 times)

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
OPEN SOCKET FROM PLC TO a FTP server.
« on: April 19, 2020, 09:14:35 AM »
OPEN SOCKET FROM PLC TO a  FTP server.

1. FTP server can be enabled using Features in windows 10.
2. However, I want to use a portable FTP server.
3. BabyFTP seemed like a good candidate, but it stuck in binary mode and failed to create data socket
4. Xlight FTP, (rfc 959 IMPLEMENTATION) is my next candidate.
   First, add a new virtual server.
   Global Options include Install as service, deny/allow IP_address, Bandwidth limit, Firewall & broadband router, SSL certificate, ODBC DB config, Remote admin, logging even log to a DB. I am impressed! What a gem.
   Create a user or anonymous user with home directory.
   Hit Play to start the server.

From PLC, open socket to the target with port 21, then send commands
 // Not needed if send directly from PLC, Testing with Hercules
Code: [Select]
OPEN 192.168.0.44   
Response = 220 Xlight FTP Server 3.9 ready...

Your socket program need to check the response and act on it that is to give the USER as next command

Code: [Select]
USER ANONYMOUS$0D$0AResponse = 331 Anonymous login OK, send your e-mail as password

Code: [Select]
PASS FTP$0D$0AResponse = 230 Login OK

(not need TYPE ASCII)

Code: [Select]
EPSV$0D$0A              
229 Entering Passive Mode (|||54732|)

PLC needs to parse out and retain the port 54732

Code: [Select]
RETR TestData.txt$0D$0A150 Opening BINARY mode data connection for TestData.txt (30 bytes).

At this point, I need to connect to the data socket channel on port 54732 to view the content of the file:

Connected to 192.168.0.44
#CR#LF#CR#LFTHIS IS A TEST 99999  #CR#LF#CR#LF

Finally, parse the content to string tag



« Last Edit: April 19, 2020, 09:30:04 AM by bachphi »
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: OPEN SOCKET FROM PLC TO a FTP server.
« Reply #1 on: April 23, 2020, 11:50:39 AM »
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: OPEN SOCKET FROM PLC TO a FTP server.
« Reply #2 on: February 26, 2022, 02:46:59 PM »
Similar approach can be carried out to read/write from a web server. Open socket to port 80 HTTP instead.

To read a typical index webpage
GET / HTTP/1.1$r$lHost:www.example.com$r$l$r$l

To POST:
POST /upprnt1.cgi HTTP/1.1$r$lHost:www.example.com$r$l
Content-type: multipart/form-data; boundary=bound$r$l
Content-Length: 241$r$l$r$l
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================