charonn0 / RB-FTP

FTP client and server implementations in realbasic
MIT License
10 stars 4 forks source link

Close DataBuffer #8

Closed SurferJoe closed 8 years ago

SurferJoe commented 8 years ago

I think you need to close the DataBuffer when the TransferComplete Fires; otherwise you cannot call store again on the same file without some problems.

Sub TransferComplete(UserAborted As Boolean)

pragma Unused UserAborted

Me.CloseData() DataBuffer.Close DoResponse(226, "Transfer complete.") End Sub

charonn0 commented 8 years ago

Have you encountered any problems? The server class's TransferComplete event is currently only raised for downloads (server->client). Upload (client->server) completion is handled in the Server.STORHandler method which does close the buffer (though it probably should raise TransferComplete too.)

SurferJoe commented 8 years ago

I found that after I uploaded a file a file and tried to save back over the file that it wasn't properly closed. So I couldn't access it or overwrite it. This is on a Mac so that might make a difference.

charonn0 commented 8 years ago

Where exactly does the file you want to overwrite exist: on the client or server? Can you provide some example code that triggers the problem?

SurferJoe commented 8 years ago

The file resides on the client side.

So if I upload a text file and later try to write to that same text file it throws an exception because the file was not properly closed

The actual scenario looks a little like this.

f = New FolderItem( path + fileName, FolderItem.PathTypeNative ) If f <> Nil Then Dim fileStream As TextOutputStream fileStream = TextOutputStream.Create( f ) fileStream.Write ConvertEncoding( "Some Text", Encodings.UTF8 ) fileStream.Close fileStream = Nil If f.Exists Then Client.STOR( path, f, mode ) End If End If

Then a text change is made and the method is run again the exception will occur when trying to create a TextOutputStream i.e.

fileStream = TextOutputStream.Create( f )

Hope this helps, by the way this is a great chunk of code.

charonn0 commented 8 years ago

You were right about not closing the stream. But, your original suggestion is for code in the server class which is not used when uploading to a remote server. I think this change to the FTP.Client class fixes it.