How to do APPEND

Jul 17, 2012 at 4:18 PM

I was looking at the API reference file and did not find a method to perform APPEND instead of Upload. Is there a way to do this?

Jul 17, 2012 at 4:22 PM
The rest parameter of the overloaded upload methods sets the restart position. In the case of IIS, the APPE command is used instead of REST + STOR which means with IIS you can't set an exact restart position on the server side, it just appends to the file. Checking the file size of the remote file and passing it to the rest parameter should work for most cases.
Jul 17, 2012 at 4:41 PM

Thanks for your quick reply. I'll give it a try with the rest parameter.

Jul 26, 2012 at 5:43 PM

As per your suggestion, It worked for IIS and FileZilla. I need to get it working for OS/400. It looks like OS/400 does not support REST and SIZE but it does support APPE. Is there a way to force APPEND when calling the Upload method?

Jul 26, 2012 at 5:45 PM
If you don't mind send me a copy of the FEAT list from the transaction log and I'll see about getting a work around for you in place.
Jul 26, 2012 at 6:01 PM

I've emailed you the FEAT list. Thanks for helping with this.

Jul 26, 2012 at 6:07 PM
No problem, will try to get a fix in today.
Jul 26, 2012 at 6:53 PM

Alright, the latest revision 7d818b50994a has a new property in FtpClient called UseAppendForUploadResume. I added a check for OS/400 the same way as IIS was checked so you shouldn't have to change anything in your code however if you explicitly change this value it will override the auto-detection and use REST + STOR or APPE according to the value you set. Let me know if this clears up the problem.

Jul 26, 2012 at 8:32 PM

Thanks a lot for your rapid fix. I try it out and let you know.

Jul 27, 2012 at 9:58 PM

It continues to use the STOR command when i call the Upload(localfile, remotefile) method with UseAppendForUploadResume property set by the checking you've added. In order to get it to work (For enforcing APPE), i had to call other overloaded methods of Upload with rest parameter and pass a value greater than 0 for rest parameter.

I think the logic of the following code in OpenWrite method needs to be changed. You may want to remove the rest > 0 condition.

            if (rest > 0 && this.UseAppendForUploadResume) {
                cmd = string.Format("APPE {0}", path);

Jul 27, 2012 at 10:07 PM
Edited Jul 27, 2012 at 10:11 PM

Yes, it's confusing as hell. Definitely a hack. I pushed up a new revision today that has new OpenWrite() and Upload() overloads that have a bool append parameter. I believe these methods are less confusing and will do what you want. I started to remove the UseAppendForUploadResume method this morning but I held off. I'm going to think on it over the weekend and make a decision next week. The new OpenWrite and Upload methods will remain and so I think that is probably the best path forward for you. The only tricky  part about the new append methods is that if you want to resume the upload from a certain point locally, you need to open a file stream and seek it to the proper location before beginning the append process. The commit comments in the source section of the site have a quick an dirty example.

So, I don't want to change the behavior or API any more right now. It's getting kind of messy and I really need to think it through to find something that is going to work long term and not confuse people trying to understand the behavior of the code.

Jul 30, 2012 at 4:22 PM

Thanks again for the quick fix. It works like a charm with new overload of Upload() method with append parameter. I believe you are moving in the right direction. As i do not need to do resume with append in my case now, i have yet to test that. I really appreciate your help in getting this fixed very quickly.

Jul 30, 2012 at 4:27 PM
Not a problem. I uploaded a new revision today that has lots of
changes. I've deprecated the OpenRead() and OpenWrite() methods in
favor of a new OpenFile() method that lets you specify Read / Write /
Append. I've also deprecated the property for forcing the use APPE
instead of STOR. I think the new code is much less confusing than
where things were headed previously.