Differences

This shows you the differences between the selected revisions of the page.

library_session_putfiles 2011-12-29 library_session_putfiles 2022-08-12 (current)
Line 1: Line 1:
====== Session.PutFiles Method ====== ====== Session.PutFiles Method ======
[[task_upload|Uploads]] one or more files from local directory to remote directory. [[task_upload|Uploads]] one or more files from local directory to remote directory.
 +
 +You can have WinSCP [[guide_automation#generating|generate a code template]] for ''Session.PutFiles'' for you.
 +
 +The method is quite powerful, but due to a wide range of it uses, its syntax can be cumbersome initially. For specific tasks, consider using convenient alternatives: [[library_session_putfilestodirectory|''Session.PutFilesToDirectory'']] and [[library_session_putfiletodirectory|''Session.PutFileToDirectory'']].
===== Syntax ===== ===== Syntax =====
-<code csharp> +<code csharp *
-public OperationResult<TransferArgs> PutFiles(+public TransferOperationResult PutFiles(
    string localPath,     string localPath,
    string remotePath,     string remotePath,
Line 12: Line 16:
</code> </code>
-==== Parameters ====+<code vbnet *> 
 +Public Function PutFiles( 
 +    localPath As String, 
 +    remotePath As String, 
 +    Optional remove As Boolean = False
 +    Optional options As TransferOptions = Nothing 
 +) As TransferOperationResult 
 +</code> 
 + 
 +==== [[parameters]] Parameters ====
^ Name ^ Description ^ ^ Name ^ Description ^
-| string localPath | Full path to local file or directory to upload. Filename in the path can be replaced with Windows wildcard ((Windows wildcard supports ''*'' and ''?'' only. It does not support all the features of [[file_mask|file masks]].)) to select multiple files. When file name is omited (path ends with backslash), all files and subdirectories in the local directory are uploaded. | +| string ==localPath== | Full path to local file or directory to upload. Filename in the path can be replaced with Windows wildcard ((The Windows wildcard supports ''*'' and ''?'' only. If you want to use a full syntax of [[file_mask|file masks]], use a ''[[library_transferoptions#filemask|TransferOptions.FileMask]]''.)) to select multiple files. To upload all files in a directory, use mask ''*''. | 
-| string remotePath | Full path to upload the file to. When uploading multiple files, the filename in the path should be replaced with [[operation_mask|operation mask]] or omited (path ends with slash). | +| string ==remotePath== | Full path to upload the file to. When uploading multiple files, the filename in the path should be replaced with [[operation_mask|operation mask]] or omitted (path ends with slash). | 
-| bool remove | When set to ''true'', deletes source local file(s) after transfer. Defaults to ''false''. | +| bool ==remove== | When set to ''true'', deletes source local file(s) after a successful transfer. Defaults to ''false''. | 
-| [[library_transferoptions|TransferOptions]] options | Transfer options. Defaults to ''null'', what is equivalent to ''new TransferOptions()''. |+| [[library_transferoptions|TransferOptions]] ==options== | Transfer options. Defaults to ''null'', what is equivalent to ''new TransferOptions()''. |
==== Return Value ==== ==== Return Value ====
-''[[library_operationresult|OperationResult<T>]]'' holding collection of ''[[library_transferargs|TransferArgs]]''. See also [[library_session#results|Capturing results of operations]].+''[[library_transferoperationresult|TransferOperationResult]]''. See also [[library_session#results|Capturing results of operations]].
-===== Exceptions =====+===== [[exceptions]] Exceptions =====
^ Exception ^ Condition ^ ^ Exception ^ Condition ^
| InvalidOperationException | Session is not opened. | | InvalidOperationException | Session is not opened. |
| ArgumentException \\ ArgumentOutOfRangeException | Invalid combination of values of ''[[library_transferoptions|TransferOptions]]'' properties. | | ArgumentException \\ ArgumentOutOfRangeException | Invalid combination of values of ''[[library_transferoptions|TransferOptions]]'' properties. |
| [[library_sessionlocalexception|SessionLocalException]] | Error communicating with ''[[executables#winscp.com|winscp.com]]''. \\ See the exception documentation for details. | | [[library_sessionlocalexception|SessionLocalException]] | Error communicating with ''[[executables#winscp.com|winscp.com]]''. \\ See the exception documentation for details. |
 +| [[library_sessionremoteexception|SessionRemoteException]] | Session has failed. \\ Uploading of files has failed. \\ See the exception documentation for details. |
| TimeoutException | Timeout waiting for ''winscp.com'' to respond. | | TimeoutException | Timeout waiting for ''winscp.com'' to respond. |
===== Remarks ===== ===== Remarks =====
-Event ''[[library_session_filetransferred|Session.FileTransferred]]'' is raised for every uploaded file.+Event ''[[library_session_filetransferred|Session.FileTransferred]]'' is raised for every uploaded file. Also raises [[library_session_filetransferprogress|''Session.FileTransferProgress'']] throughout the transfer. 
 + 
 +The upload aborts on the first error. See the example on [[library_example_recursive_download_custom_error_handling|implementing recursive directory tree download with custom error handling]]. Uploads can be implemented similarly too, see an example of [[library_example_moves_files_keeping_directory_structure|implementing recursive directory tree upload]]. 
 + 
 +===== Example ===== 
 +See [[library#example|overall example for WinSCP .NET assembly]]. 
 + 
 +==== Real-Life Examples ====
 +  * [[script_local_move_after_successful_upload|*]];
 +  * [[script_locking_files_while_uploading|*]];
 +  * [[library_example_moves_files_keeping_directory_structure|*]].
-~~NOTOC~~ 

Last modified: by martin