A bunch of programs for computercraft
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
808 B

os.loadAPI('/lib/cnt')
local tArgs = { ... }
if #tArgs < 1 then
print( "Usage: getFile <remote_file> [local_file]" )
return
end
local r_filename = tArgs[1]
local l_filename = shell.resolve(fs.getName(r_filename))
print(l_filename)
tmp = fs.open('/etc/ftp.conf','r')
local fileserver = tostring(tmp.readLine())
fs_id = cnt.lookup(fileserver)
message=textutils.serialize({'FTP',r_filename})
rednet.send(fs_id,message)
local senderId, reply, distance = rednet.receive()
reply = textutils.unserialize(reply)
while senderId ~= fs_id and reply[1] ~= 'FTP' do
local senderId, reply, distance = rednet.receive()
reply = textutils.unserialize(reply)
end
if reply[2] > 0 then
l_file=fs.open(l_filename,'w')
l_file.write(reply[3])
l_file.close()
else
print("File not found: "..r_filename)
end