[Up]: Storage API : CopyMove

CopyMove

Script path: /storage/bin/api/copymove.cgi

Description: Copies/Moves a source item (file/folder) to another specifically named target item, or into a target folder, with the target item adopting the source's name. Move is essentially similar to Copy, except that the source item is also deleted. Parameter "move" is used to specify a move or copy operation. If a target file exists, it can be optionally replaced. This however, apply to existing target folders in a different manner. Existing target folder (and their subfolders) are never replaced. It is the files within them that are subjected being replaced.

INPUT (via GET or POST)

Mandatory parameters are: sid, path, tpath
Optional parameters are: move, replace, ofmt

sid session id of the login user. [mandatory]
path path to an item [mandatory]

Please refer to [How to specify a path].

path must point to an existing file or folder.

e.g.
path=/Private/MyFile.avi  - copy or move the file MyFile.avi of "Private" area
path=/Company Share/Archive/Data/ - copy or move folder Data.
 

tpath = path to the target item [mandatory]
= or path to the folder to contain target item.

tpath need not point to an existing file or folder. But the folder (parent) to contain the yet-to-be-created item must itself exist.

tpath has the same format as "path" but the trailing "/" is significant.

A tpath without a trailing "/" means a fully qualified path to an target item, whether a file or folder. This is what the source item will be copied/moved to. This allows the target to be of a different name from the source. If this item does not exist it will be created. If this item exists, then the "replace" parameter can be used to replace the item (a file) or the files within the item (a folder).

A tpath with a trailing "/" means that it specifies an existing folder into which the source item (file/folder) is to be copied/moved. The targeted item will adopt the same name and type (file/folder) as the source. The "replace" parameter takes the same meaning here.

e.g.
tpath=/Private/subdir/subdir - if source is a folder, then this is taken to be the target folder which will hold
the same content as source.

tpath=/Private/subdir/subdir/ - specifying a folder into which the source item will end up.

tpath=/Private/ - Unlike path, tpath can take this form to receive source items into the top storage area.

When a new file or folder is specified with tpath, the name is subjected to set of rescrictions. Please refer to [Name restriction] for details.

 

move = yes
Indicates a move operation. By default (when unspecified or when not= "yes"), a copy operation is performed.
 
replace = yes
Indicates that files will be replaced (copied over) if the target has files of the same name. The default behavior is not to replace existing files, and return an error.

ofmt
= null | json | jsonp
   null is the default, and the legacy "flat" output format is returned.
   json means the output format is in JSON format
   jsonp is like json, but in "pretty" form for easier human readability
 

NOTE: File replacement is still subject to other permission to replace that file. E.g. if you don't own the existing file, you are unlikely to be able to replace it even with replace=yes.

NOTE: Replacement of folders does NOT arise during a folder copy/move. That is because it is taken to mean recursive copy/move of files within the folder. Folders (and subfolders) being copied are simply created if they do not exist in the target. If they exist then nothing else is done. What could be replaced are the files in the folder.

 

OUTPUT (content-type: text/plain)

Successful return:

	true <newline>

          Equivalent JSON output would look like the following:

	{
"status" : true
}

Unsuccessful return:

	false <tab> <error message> <newline>

        e.g.

	false <TAB> Not replacing an existing file.

false <TAB> Permission denied to replace file.

false <TAB> Cannot move a folder into itself.

false <TAB> Permission denied to create folder.

       Equivalent JSON output would look like the following:

	{
"http_status" : "400 Unable to copy item",
"status" : false,
"errmsg" : "Permission denied to create folder"
}

   In both legacy "flat" output and also JSON output, appropriate HTTP header status codes are also returned e.g. 200 OK, 401 Invalid user profile, etc.