FTP Code Example: Resume an upload

If your transfer is interrupted you can use the StartByte property of the FTP component to resume the transfer.

Date Entered: 04/02/2008    Last Updated: 02/10/2017

The StartByte property contains a zero-based index in both RemoteFile and LocalFile that determines the point where the transmission of data starts from. Once set, the StartByte index is used for all future downloads/uploads. The property must be reset to "0" for normal downloads/uploads. The code below demonstrates how this property can be used to resume an upload.

Note that FileSize is an action property. When queried it will ask the server for the size of the file specified by the RemoteFile property.

C# ftp.LocalFile = @"C:\LocalFile.txt"; ftp.RemoteFile = "RemoteFile.txt"; ftp.StartByte = ftp.FileSize.ToString(); ftp.Upload(); ftp.StartByte = "0";
Java ftp.setLocalFile("C:\\LocalFile.txt"); ftp.setRemoteFile("RemoteFile.txt"); ftp.setStartByte(String.valueOf(ftp.getFileSize())); ftp.upload(); ftp.setStartByte("0");

We appreciate your feedback.  If you have any questions, comments, or suggestions about this entry please contact our support team at kb@nsoftware.com.