Version: 4.5.0.0
Easily add comprehensive, secure FTP to any .NET application or service.

Append To A Remote File Code Example

The following example demonstrates a session in which data is appended to a file on the server. The same technique can be used to resume an interrupted transfer.

< Back to all samples for PowerTCP FTP for .NET

private void updateRemoteLog()
{
    //Append new local file data to a remote file
    ftp1.Session.RemoteEndPoint.HostNameOrAddress = myServer;
    ftp1.Session.Username = myUsername;
    ftp1.Session.Password = myPassword;
    ftp1.Connect();
    ftp1.Authenticate();

    //Make sure the server supports restart and size
    if (ftp1.Features.Restart && ftp1.Features.Size)
    {
        //Server has a log file that data is periodically added to
        //Get size of file on server
        long size = ftp1.GetSize("update.log");

        //using System.IO
        FileStream localLogFile = new FileStream(myLogFile, FileMode.Open, FileAccess.Read);

        //Set position to remote file size
        localLogFile.Position = size;

        //Get the new data in the file and append it to the remote file
        ftp1.Put(localLogFile, "update.log", 0, StoreType.Append);
        localLogFile.Close();
    }
    ftp1.Close();
}