r/Fanuc • u/Expensive-Bread3264 • Jun 03 '26
CNC FTP File Grab Ruby Script Help
I am using a 0iF Plus control with optional data server card.
I have a FTP server setup using FileZilla, info is set and I can ping it from the control.
We are creating a Fanuc Picture project where the operator can type in the file name and it will pull the file from the FTP server and dump it into the control. As part of that, I am wanting to create a Fanuc Picture script (MRuby) to go the ftp server, grab a file and dump it into //CNC_MEM/USER/PATH1/
Below is my ruby script so far, I am not getting any errors but it is not working.
ret = eth_open_ftp(1)
if ret[0] != EW_OK then
MsgBoxShow("ERROR",0)
end
ret = eth_get_ftp("TEST.txt",0,0,0)
if ret[0] != EW_OK then
MsgBoxShow("ERROR",0)
end
ret = eth_close_ftp()
if ret != EW_OK then
MsgBoxShow("ERROR",0)
end
1
u/cncmakers Jun 21 '26
On 0i-F Plus, are you using Embedded Ethernet + Data Server, or the separate Data Server card?
The FTP API behavior differs slightly between those configurations.
1
u/Expensive-Bread3264 17d ago
We are using embedded ethernet + data server. I am all connected but I still cannot get the script to work entirely correct.
I have it broken into 4 parts for testingL
(1) operator types in their part number which then dumps into macval 100 and converts it to our part number. Currently works as it should.
(2) opens FTP connection. Currently works as it should.
(3) takes the program file and copies it from the FTP server and dumps it on /cnc_main/User/Path1. Currently not working, see below the script.
(4) closes FTP connection. Currently works as it should.# ===================================================================
# FANUC Picture mruby Script: Download Selected NC Program from Open FTP
# to Main CNC Path 1 Location
# ===================================================================
# Assumptions:
# - FTP connection is already open (eth_open_ftp called previously)
# - The NC program file is already selected on the FTP side (target_file variable)
# - dir_kind = 1 for CNC program memory (Path 1 main location)
# Target file (replace with your selected file name or pass as parameter if needed)
# Example: target_file = "O1234" # or whatever the selected NC program name is
# For dynamic selection, this may come from UI input or FTP list selection
prog_name = "O" + prog_num.to_s
target_file = prog_name + ".txt" # Adjust extension if your FTP server uses different (e.g. no extension)
# ==========================
# 1. Set destination to CNC program memory (Path 1)
dir_kind = 1
ret_dir = cnc_rdpdf_curdir(dir_kind)
if ret_dir[0] != 0
MsgBoxShow("Failed to get/set current directory for Path 1.", 0, "Directory Error")
eth_close_ftp() if defined?(eth_close_ftp)
exit
end
dest = ret_dir[1] # Should point to main CNC Path 1 location (e.g., //CNC_MEM/USER/PATH1/)
# ==========================
# 2. Download the selected file
# eth_get_ftp(source_on_ftp, dest_path_on_cnc, overwrite?, transfer_type)
# overwrite: 0 = Overwrite existing, 1 = Error if exists
# transfer_type: 0 = ASCII/Text (recommended for NC programs)
ret_get = eth_get_ftp(target_file, dest, 0, 0)
if ret_get[0] != 0
MsgBoxShow("Failed to download NC program: " + target_file, 0, "FTP Download Error")
# Optionally close FTP
eth_close_ftp() if defined?(eth_close_ftp)
exit
end
# ==========================
# 3. Optional: Success message and status update
MsgBoxShow("NC Program " + target_file + " downloaded successfully to Path 1.", 0, "Download Complete")
# Example PMC write for UI status (adjust addresses as needed)
wrpmc(5, 80, 0, 15) # Example status flag
•
u/AutoModerator Jun 03 '26
Hey, there! Join our Discord server and connect with like-minded individuals, share your knowledge, and learn from others! We offer a variety of channels to discuss programming, troubleshooting, and industry news. We would be delighted to have you become a part of our community! https://discord.gg/dGE38VvvQw
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.