General Category > Tips & Tricks
OPEN SOCKET FROM PLC TO a FTP server.
(1/1)
bachphi:
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: ---OPEN 192.168.0.44
--- End code ---
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: ---USER ANONYMOUS$0D$0A
--- End code ---
Response = 331 Anonymous login OK, send your e-mail as password
--- Code: ---PASS FTP$0D$0A
--- End code ---
Response = 230 Login OK
(not need TYPE ASCII)
--- Code: ---EPSV$0D$0A
--- End code ---
229 Entering Passive Mode (|||54732|)
PLC needs to parse out and retain the port 54732
--- Code: ---RETR TestData.txt$0D$0A
--- End code ---
150 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
bachphi:
bachphi:
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
Navigation
[0] Message Index
Go to full version