|
Upload a file There exist several ways to upload the file to the remote server. First way is to use UploadStream() or UploadFile() method of TElSimpleSFTPClient class to upload a single data block which makes a file. UploadStream() method accepts a reference to the data stream (be it file stream, or memory stream, or BLOB stream or some other stream). UploadFile() method accepts the name of the local file. Another parameter for the above mentioned methods is the absolute path to the remote file (SFTP doesn't have a concept of "current directory"). If you have more than one file to upload, you can use UploadFiles() method of TElSimpleSFTPClient class. This method accepts the local folder, the standard file mask for local files and the absolute path to the remote directory (SFTP doesn't have a concept of "current directory"), where the files will be placed. The method lets you perform case conversion of the file names during file upload. Both UploadStream(), UploadFile() and UploadFiles() accept the last parameter, which specifies the way how the component behaves when the remote file with the specified name exists. Possible options are (a) skip the existing file, (b) append the data to the end of the remote file, (c) resume the transfer, if the size of the remote data is less than size of the local file and (d) overwrite the data completely. The application is notified about the progress of the single file upload operation using OnProgress event of TElSimpleSFTPClient class. UploadFiles() also notifies the application, when the next file is to be processed, using OnFileOperation() event of TElSimpleSFTPClient class. Using both events you can cancel the upload operation. The most sophisticated and flexible way is to use OpenFile/Write/ CloseHandle sequence of methods. Use OpenFile() or CreateFile() method of TElSimpleSFTPClient class to open or create the file and get a file handle. The next step is to use Write() method to transfer the data. Don't pass the whole data block to this method. Use chunks which are smaller than 1 Mb. When you finish writing the data, use CloseHandle() method to close the file. All of the above methods are synchronous and return when the operation is completed. For information about error handling, see the corresponding how-to article. |

