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



Absolute or relative destination file path.
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.
Lowest level Put method starts upload to the specified offset.
Syntax
Public Overloads Function Put( _
   ByVal remotePath As String, _
   ByVal remoteOffset As Long, _
   ByVal storeType As StoreType _
) As Stream
Dim instance As Ftp
Dim remotePath As String
Dim remoteOffset As Long
Dim storeType As StoreType
Dim value As Stream
 
value = instance.Put(remotePath, remoteOffset, storeType)
public Stream Put( 
   string remotePath,
   long remoteOffset,
   StoreType storeType
)
public:
Stream^ Put( 
   String^ remotePath,
   int64 remoteOffset,
   StoreType storeType
) 

Parameters

remotePath
Absolute or relative destination file path.
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

A Stream to write to.
Remarks

The returned stream must be closed before sending more commands over the control connection (the server response to the store command is read when the stream is closed).

DataIsBusy returns true until the stream this method opens is closed.

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 using a stream to process data as it is uploaded to the server.
private void processRecords()
{
    //Open the local file for transfer, with 'using' so it is automatically closed and disposed
    using (FileStream localFileStream = File.OpenRead(myRecordsFile))
    {
        //Request a stream for writing to the remote file, with 'using' so it is automatically closed and disposed
        using (Stream remoteStream = ftp1.Put(myRecordsFile, 0, StoreType.Replace))
        {
            //Create the buffer to read data into for transfer.
            //In this example, each record is 64 bytes, but not delimited
            byte[] buffer = new byte[64];

            //Create the end of record tag as a byte array.
            byte[] endOfRecord = System.Text.Encoding.Default.GetBytes("[END OF RECORD]" + Environment.NewLine);

            int count = -1;

            //Write until all local file records are written.
            do
            {
                //Read the data into the buffer.
                count = localFileStream.Read(buffer, 0, buffer.Length);

                //Write the record to the remote file. 
                remoteStream.Write(buffer, 0, buffer.Length);

                //Write the end of record tag.
                remoteStream.Write(endOfRecord, 0, endOfRecord.Length);
            } while (count > 0);
        }
    }
}
Private Sub processRecords()
    'Open the local file for transfer, with 'using' so it is automatically closed and disposed
    Using localFileStream As FileStream = File.OpenRead(myRecordsFile)
        'Request a stream for writing to the remote file, with 'using' so it is automatically closed and disposed
        Using remoteStream As Stream = ftp1.Put(myRecordsFile, 0, StoreType.Replace)
            'Create the buffer to read data into for transfer.
            'In this example, each record is 64 bytes, but not delimited
            Dim buffer(63) As Byte

            'Create the end of record tag as a byte array.
            Dim endOfRecord() As Byte = System.Text.Encoding.Default.GetBytes("[END OF RECORD]" & Environment.NewLine)

            Dim count As Integer = -1

            'Write until all local file records are written.
            Do
                'Read the data into the buffer.
                count = localFileStream.Read(buffer, 0, buffer.Length)

                'Write the record to the remote file. 
                remoteStream.Write(buffer, 0, buffer.Length)

                'Write the end of record tag.
                remoteStream.Write(endOfRecord, 0, endOfRecord.Length)
            Loop While count > 0
        End Using
    End Using
End Sub
See Also

Reference

Ftp Class
Ftp Members
Overload List


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