tags:

views:

163

answers:

1

I'm trying to use wxFTP on wxLua to upload several files. It works with the 1st file, but I do not understand why I cannot send a 2nd file. Here is a sample that fails :

local ftp = wx.wxFTP()
local ftpAddress = wx.wxIPV4address()
ftpAddress:Service( "ftp" )
ftpAddress:Hostname( "ftp.example.com" )
ftp:Connect( ftpAddress )
local out1 = ftp:GetOutputStream( "foo" )
out1:Close()
local out2 = ftp:GetOutputStream( "bar" )
out2:Close() -- here out2 is nil
+1  A: 

Instead of calling Close on the output stream set the variable to nil and let the garbage collector handle it. wxOutputStream is actually a pointer to a wxFTPOutputStream that inherits from wxSocketOuputStream. The Close method doesn't do anything -- it always returns true -- and the stream must be destroyed (i.e. the destructor called) to close the socket.

Try this:

local ftp = wx.wxFTP()
local ftpAddress = wx.wxIPV4address()
ftpAddress:Service( "ftp" )
ftpAddress:Hostname( "ftp.example.com" )
ftp:Connect( ftpAddress )
local out1 = ftp:GetOutputStream( "foo" )
out1 = nil
collectgarbage("collect")  -- force full garbage collection
local out2 = ftp:GetOutputStream( "bar" )
out2 = nil
collectgarbage("collect")
Judge Maygarden
Well, in fact, I tried this, and it still fails.
Jazz