Automatic FTP synchronization (server to server transfer)

You can share your Lua Scripts with everybody here.
Post Reply
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Automatic FTP synchronization (server to server transfer)

Post by FTP »

-- Description: Automatic FTP synchronization or backup (server to server transfer)
-- You should add the below scripts to the event manager -> FTP or HTTP OnFileUploaded
-- When a file is uploaded, it can be sent to one or two or even more FTP servers automatically
-- Author: Luke
-- Date: 2012-10-07

Code: Select all

require("socket.ftp")
require("socket.ltn12")

--send the file to the first FTP server
f, e = put{
  host = "192.168.0.100", 
  user = "user1",
  password = "pass1",
  port = 21,
  argument = "/%FileName",
  source = source.file(io.open("%PathName", "rb"))
} 

--send the file to the second FTP server
f, e = put{
  host = "192.168.0.105", 
  user = "user2",
  password = "pass2",
  port = 21,
  argument = "/ftpfolder/%FileName",
  source = source.file(io.open("%PathName", "rb"))
} 
Image


The above scripts use a modified version of luasocket library, you can download and unzip it into the working directory of Wing FTP Server. The download URL: https://www.wftpserver.com/bbsres/socket.zip
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: Automatic FTP synchronization or backup

Post by FTP »

You can also use the luasocket library for downloading a file:

Code: Select all

require("socket.ftp")
require("socket.ltn12")

f, e = get{
  host = "192.168.0.100", 
  user = "USERNAME",
  password = "PASSWORD",
  port = 21,
  argument = "img111.jpg",
  sink  = sink.file(io.open("c:/img111.jpg", "wb"))
} 
Post Reply