FTP return codes

Aug 3, 2007 at 12:20 PM
THis was from a discussion started on codeproject. Your upload routines do not return the values from the FTP server. You previously said that it is not needed becasue the try catch will catch everything. I think the return codes from your FTP server are important. As an example: if you are uploading a file to the wrong area the command iteself will return a value but the file will not be transferred. You should get a return code from the FTP server that will indicate that. A suggessstion is to create a return value attribute and a return description attribute. This would enable anyone using this to query for the exact return code. As a test I did this
Dim ftp As New Utilities.FTP.FTPclient("xxxx", "yyyyyy", "zzzzzzz")
ftp.Upload("d:\test.txt", "/opt/test.txt")

This tries to put a file in the /opt directory on my local Unix workstation. The upload process does not abort or generate an exception but the file is still not present becasue I do not have rights to the /opt directory. I added a Get response check to your code and then ran my test. It turns out I did get an exception becasue I was not handling the response.

My point is that if FTP response codes can be important and should be captured.
Aug 3, 2007 at 1:07 PM
I am working on trying to capturing the return codes. It appears that when you do this
Try
response = ftp.GetResponse
Catch wex As WebException
MessageBox.Show(wex.Response.tostring)
Finally
response.Close()
in the above situation you just get system.net.ftpwebresponse

If you change it to this wex.message.tostring you will get a message that has the servers reponse in it. I have not yet figured out how to get teh servers response but it should be possible.
Aug 3, 2007 at 1:33 PM
I figured out a way to do this. The below code does return the error codes but you have to catch them in an excception block using the GetResponse method. While the below code is not robust enough for inclusion into a standalone DLL it is robust enough for my needs
Try
Dim response As FtpWebResponse = CType(ftp.GetResponse(), FtpWebResponse)
Catch e As WebException
Console.WriteLine(e.Message)

If e.Status = WebExceptionStatus.ProtocolError Then
MessageBox.Show("Status Code : " & CType(e.Response, FtpWebResponse).StatusCode)
MessageBox.Show("Status Description : " & CType(e.Response, FtpWebResponse).StatusDescription)
End If
End Try

Is capturing the response code something yo mig be interested in putting in your code?
Coordinator
Aug 6, 2007 at 4:34 PM

Thanks for the feedback. I don't process the response codes, that's right (when originally written I was on beta2 of .NET 2.0 and had no documentation!) - will investigate
Coordinator
Aug 6, 2007 at 4:36 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.