PowerTCP FTP for .NET
Put(Stream,String,Int64,StoreType) Method
Example 



Source stream to read from.
Absolute or relative destination filepath.
Restart marker to which the data transfer should start. Used when storeType is StoreType.Replace.
The type of store to use. If remoteOffset > 0 then storeType must be StoreType.Replace.
Starts upload from the current position in the specified source stream and writes to the destination file at the specified offset.
Syntax
Public Overloads Function Put( _
   ByVal localSource As Stream, _
   ByVal remotePath As String, _
   ByVal remoteOffset As Long, _
   ByVal storeType As StoreType _
) As CopyResult
Dim instance As Ftp
Dim localSource As Stream
Dim remotePath As String
Dim remoteOffset As Long
Dim storeType As StoreType
Dim value As CopyResult
 
value = instance.Put(localSource, remotePath, remoteOffset, storeType)

Parameters

localSource
Source stream to read from.
remotePath
Absolute or relative destination filepath.
remoteOffset
Restart marker to which the data transfer should start. Used when storeType is StoreType.Replace.
storeType
The type of store to use. If remoteOffset > 0 then storeType must be StoreType.Replace.

Return Value

CopyResult containing the result of the operation.
Remarks

The source Stream is not closed.

DataIsBusy returns true while this method executes.

Characters specified in the remote path are sent to the server unmodified. If the path contains characters that are invalid for the server host filesystem, it may cause the operation to fail with an FtpProtocolException.

Example
The following example demonstrates restarting/resuming a Put.
/// <summary>
/// Resumes a Put operation
/// </summary>
/// <param name="myFtp">A connected and authenticated Ftp instance</param>
/// <param name="localPath">Path to the local file</param>
/// <param name="remotePath">An absolute or relative path to the file on the server</param>
/// <returns>The CopyResult of the operation</returns>
public CopyResult RestartPut(Ftp myFtp, string localPath, string remotePath)
{
    //Check that the server advertises/supports features required to resume a Put
    if (!myFtp.Features.Size || !myFtp.Features.Restart)
        throw new Exception("Server doesn't support features required to restart a Put");

    //Ensure that the Ftp object is in binary/image transfer mode
    myFtp.SetType(FileType.Image);

    //Get the size of the remote file
    long offset = myFtp.GetSize(remotePath);

    using (FileStream fs = File.OpenRead(localPath))
    {
        //Set the stream to the correct position
        fs.Position = offset;
        //Resume the transfer, and (optionally) return the result
        return myFtp.Put(fs, remotePath, offset, StoreType.Replace);
    }
}
''' <summary>
''' Resumes a Put operation
''' </summary>
''' <param name="myFtp">A connected and authenticated Ftp instance</param>
''' <param name="localPath">Path to the local file</param>
''' <param name="remotePath">An absolute or relative path to the file on the server</param>
''' <returns>The CopyResult of the operation</returns>
Public Function RestartPut(ByVal myFtp As Ftp, ByVal localPath As String, ByVal remotePath As String) As CopyResult
    'Check that the server advertises/supports features required to resume a Put
    If (Not myFtp.Features.Size) OrElse (Not myFtp.Features.Restart) Then
        Throw New Exception("Server doesn't support features required to restart a Put")
    End If

    'Ensure that the Ftp object is in binary/image transfer mode
    myFtp.SetType(FileType.Image)

    'Get the size of the remote file
    Dim offset As Long = myFtp.GetSize(remotePath)

    Using fs As FileStream = File.OpenRead(localPath)
        'Set the stream to the correct position
        fs.Position = offset
        'Resume the transfer, and (optionally) return the result
        Return myFtp.Put(fs, remotePath, offset, StoreType.Replace)
    End Using
End Function
See Also

Reference

Ftp Class
Ftp Members
Overload List


PowerTCP FTP for .NET Documentation Version 6.1
© 2023 Dart Communications. All Rights Reserved.
Send comments on this topic