put_files

FunctionalityWrapper.put_files(files_on_local, style='rel_path', anon=False, overwrite=False, return_paths='input', return_content=False, read_mode='r')[source]

Copies the files defined in files_on_local to the sever. After ‘uploading’ the files it returns a list of paths or content_dicts depending on return_content

Parameters:
  • files_on_local (str, dict, list of str/dict, iterable of str/dict) –

    Path/-s to the local file/-s which should be copied to the server.

    str/list of str:
    all files will be copied to the chosen root.
    dict/list of dict:
    files_on_local[“src”]:
    gives the local file path and
    files_on_local[“dest”]:
    gives the relative path the file on the server.
  • style ({'rel_path', 'url'}, default 'rel_path') –
    ‘rel_path’:
    path relative to server_home/anon_root is returned.
    ’url’:
    url to the file is returned.
  • anon (bool) –
    True:
    Use anon_root as basepath
    False:
    Use server_home as basepath
  • overwrite (bool, default False) –
    True:
    overwrites file without warning
    False:
    warns the user if a file exists and doesn’t overwrite it
  • return_paths ({'all', 'input', 'new'}, default 'input') –
    ‘all’:
    Return all files in the server_home/anon_root.
    ’input’:
    Return files in the server_home/anon_root, which were added by put_files.
    ’new’:
    Return only changed files in the server_home/anon_root, which were added by put_files.
  • return_content (bool, default False) –
    False:
    Elements of the iterable to be returned will consist of only the paths (str).
    True:
    Elements of the iterable to be returned will consist of content_dicts.
  • read_mode ({'r', 'rb'}, default 'r') – This only applies if return_content is True. Mode in which files should be read (see open("filepath", read_mode) )
Returns:

file_list – List of filepaths/content dicts in server_home/anon_root

Return type:

list

Raises:
  • TypeError – If files_on_local is not a str, dict or iterable of str/dict
  • TypeError – If style is not a str
  • TypeError – If anon is not a bool
  • TypeError – If overwrite is not a bool
  • TypeError – If return_paths is not a str
  • TypeError – If return_content is not a bool
  • TypeError – If read_mode is not a str
  • ValueError – If files_on_local is/contains an invalid filepath.
  • ValueError – If the value of style is not ‘rel_path’ or ‘url’
  • ValueError – If the value of return_paths is not ‘all’, ‘input’ or ‘new’
  • ValueError – If the value of read_mode is not ‘r’ or ‘rb’
  • KeyError – If dict or list of dicts is used for files_on_local and the dict is missing the keys ‘src’ and ‘dest’.

Examples

>>> ftpserver.put_files("test_folder/test_file", style="rel_path", anon=False)
["test_file"]
>>> ftpserver.put_files("test_folder/test_file", style="url", anon=False)
["ftp://fakeusername:qweqwe@localhost:8888/test_file"]
>>> ftpserver.put_files("test_folder/test_file", style="url", anon=True)
["ftp://localhost:8888/test_file"]
>>> ftpserver.put_files({"src": "test_folder/test_file",
...                      "dest": "remote_folder/uploaded_file"},
...                     style="url", anon=True)
["ftp://localhost:8888/remote_folder/uploaded_file"]
>>> ftpserver.put_files("test_folder/test_file", return_content=True)
[{"path": "test_file", "content": "some text in test_file"}]
>>> ftpserver.put_files("test_file.zip", return_content=True, read_mode="rb")
[{"path": "test_file.zip", "content": b'PK\x03\x04\x14\x00\x00...'}]
>>> ftpserver.put_files("test_file", return_paths="new")
UserWarning: test_file does already exist and won't be overwritten.
    Set `overwrite` to True to overwrite it anyway.
[]
>>> ftpserver.put_files("test_file", return_paths="new", overwrite=True)
["test_file"]
>>> ftpserver.put_files("test_file3", return_paths="all")
["test_file", "remote_folder/uploaded_file", "test_file.zip"]