Help Center> ModelArts> SDK Reference> OBS Management> Transferring Files (Recommended)
Updated on 2023-10-16 GMT+08:00

Transferring Files (Recommended)

Through file transferring, local files and folders can be uploaded to OBS, and the files and folders in OBS can be downloaded to a local path.

Sample Code

In ModelArts notebook, you do not need to enter authentication parameters for session authentication. For details about session authentication of other development environments, see Session Authentication.

from modelarts.session import Session 
session = Session()  
# 1. Upload a local file to OBS.
session.obs.copy(src_path='/home/ma-user/file1.txt', dst_path='obs://bucket-name/dir1/file1.txt')

# 2. Download a file from OBS to a local path.
session.obs.copy(src_path='obs://bucket-name/dir1/file1.txt', dst_path='/home/ma-user/file1.txt')

# 3. Upload a local folder to OBS.
session.obs.copy(src_path='/home/ma-user', dst_path='obs://bucket-name/dir1', keep_last_dir=True)

# 4. Download a folder from OBS to a local path.
session.obs.copy(src_path='obs://bucket-name/dir1', dst_path='/home/ma-user', keep_last_dir=True)
Table 1 Request parameters

Parameter

Mandatory

Type

Description

session

Yes

Object

Session object.

src_path

Yes

String

Path to the source file or folder. If the source path is an OBS path, the path prefix must be obs://.

dst_path

Yes

String

Path to the destination file or folder. If the destination path is an OBS path, the path prefix must be obs://.

keep_last_dir

No

Boolean

Whether to copy the last-level directory of the source folder to the destination folder. The default value is True. This parameter is valid only for copying folders.

Table 2 Failure parameters

Parameter

Type

Description

error_code

String

Error code when calling the SDK failed. This parameter is unavailable for a successful call.

error_msg

String

Error message when calling the SDK failed. This parameter is unavailable for a successful call.