format_file_path¶
-
FunctionalityWrapper.
format_file_path
(rel_file_path, style='rel_path', anon=False)[source] Formats the relative path to as relative path or url. Relative paths are relative to the server_home/anon_root, which can be used by a FTP client. Urls can be used by a browser/downloader. This method works, weather the file exists or not.
Notes
Even so taking a relative path and returning a relative path may seam pointless, this is needed to prevent errors with Windows path formatting (
\
instead of/
).Parameters: - rel_file_path (str) – Relative filepath to server_home/anon_root depending on the value of anon.
- 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:
- return the filepaths/url of file in anon_root
- False:
- return the filepaths/url of file in server_home
Returns: file_path – Relative path or url depending on the value of style
Return type: str
Raises: TypeError
– If style is not astr
TypeError
– If anon is not abool
ValueError
– If the value of style is not ‘rel_path’ or ‘url’
Examples
>>> ftpserver.format_file_path("test_folder\test_file", style="rel_path", anon=False)) test_folder/test_file
>>> ftpserver.format_file_path("test_folder/test_file", style="rel_path", anon=False)) test_folder/test_file
>>> ftpserver.format_file_path("test_folder/test_file", style="url", anon=False)) ftp://fakeusername:qweqwe@localhost:8888/test_folder/test_file
>>> ftpserver.format_file_path("test_folder/test_file", style="url", anon=True)) ftp://localhost:8888/test_folder/test_file
See also