+2 votes

Hi, I use Ftp.dll upload file to FTPS server.
My scenario is when file upload interrupted, I hope re-upload file and the file can be append not overriding.
Thank you for any help you can provide. The Ftp.dll is working fine and useful.
Best regards,
Bryan

by (310 points)

1 Answer

+1 vote

You can use Ftp.Upload method overload, that takes remoteStartPosition parameter (REST command):

public FtpResponse Upload(
    string remotePath,
    long remoteStartPosition,
    Stream source
)

...remember to seek the input stream to appropriate position before you start.

client.Upload("rest.txt", "this is ".ToByteArray());
client.Upload("rest.txt", 4, " is a test.".ToByteArray());    
byte[] downloaded = client.Download("rest.txt");

Assert.AreEqual("this is a test.".ToByteArray(), downloaded);

Please note that server must support REST extension to support this method:
You can check the value of SupportsRestStream of Ftp.Extensions property to check if this method is supported by the remote server.


You can also use Ftp.Append (APPE command):

public FtpResponse Append(
    string remotePath, 
    Stream source)

Here's the test:

client.Upload("append.txt", "this is ".ToByteArray());
client.Append("append.txt", "a test.".ToByteArray());
byte[] downloaded = client.Download(remotePath);

Assert.AreEqual("this is a test.".ToByteArray(), downloaded);
by (297k points)
edited by
Thank you for your prompt reply. And I also have two questions.
Q1:The Ftp.Append method is not working for upload append?

Q2:I install FileZilla on windows server 2012R2 and check the value of SupportsRestStream is false. So it means FileZilla is not support or maybe Windows server or FileZilla need enable something?
FileZilla server supports both: 'APPE' command (Ftp.Append), and 'REST STREAM' extension = 'REST' command (Ftp.Upload with remoteStartPosition parameter).
...