Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to copy/upload file using fs #22

Closed
blasterspike opened this issue Apr 26, 2020 · 1 comment
Closed

How to copy/upload file using fs #22

blasterspike opened this issue Apr 26, 2020 · 1 comment

Comments

@blasterspike
Copy link
Contributor

blasterspike commented Apr 26, 2020

I'm trying to understand how to copy/upload a file using pyfilesystem2.
I have tried with the following:

import fs
from pcloud import PyCloud
import urllib.parse

username = urllib.parse.quote_plus('my_username')
password = urllib.parse.quote_plus('my_password')

with fs.opener.open_fs('pcloud://{0}:{1}@/'.format(username, password)) as pcloud_fs:
    pcloud_fs.copy('/opt/software/db.sqlite3', '/backup/software/', True)

but I'm always getting

OSError: pCloud error occured (2002) - A component of parent directory does not exist.

even if /backup/software/ already exists on pCloud.
I have changed the log.debug to a print here and added a print for resp.json()
https://github.com/tomgross/pycloud/blob/31d9676446de3e417396e296dd4a95441983173e/src/pcloud/api.py#L55-L59
and this is what I'm getting back

Doing request to %s%s https://api.pcloud.com/ file_open
Params: %s {'auth': '***, 'path': '/opt/software/db.sqlite3', 'flags': 64}
{'result': 2002, 'error': 'A component of parent directory does not exist.'}

so it looks like it is inverting src_path with dst_path.

I'm using fs==2.4.11 and the copy function as from what I understand is copying files from one filesystem to another:
https://github.com/PyFilesystem/pyfilesystem2/blob/v2.4.11/fs/base.py#L401-L402

I'm trying to debug the issue but any help is appreciated.

@blasterspike
Copy link
Contributor Author

My misunderstanding. It looks like that fs.base works on the same filesystem, while if you want to copy files/directories across filesystems, you need to use fs.copy

Functions for copying resources between filesystem.
https://docs.pyfilesystem.org/en/latest/reference/copy.html

I'll see if I can create a Pull Request for the README to add some examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant