Forum Archive

Uploading tar files to dropbox

charmaex

I'm trying to upload tar files to the dropbox using this:

get_client().put_file(path_for_tar_in_db, see_below ,True)

I tried so far:

see_below = open(path,'r')
see_below = path
see_below = tarfile.open(path,'r')

Nothing helped so far.
First one makes corrupted files.
Second creates txt files.
And last one just errors.

Can somebody please help me? :)

JonB

try open (path,'rb').

charmaex

Sadly it isn't working. Still getting a ReadError :-/

ccc

You wrote:

get_client().put_file(path_for_tar_in_db, see_below, True)

but perhaps it should be:

get_client().put_file(path_for_tar_in_db, see_below, overwrite=True)


This self-archiving code works for me: tarball_to_dropbox.py

Running this puts a copy of the current script at the root of a new local .tar file and then pushes that .tar file up to Dropbox. After I run this I can open a terminal on my Mac and:

$ tar -tvf ~/Dropbox/my_archive.tar

-rw-r--r-- 0 501 501 5276 Jun 6 15:09 tarball_to_dropbox.py

$ tar -xvf ~/Dropbox/my_archive.tar

x tar_to_dropbox.py

$ cat tarball_to_dropbox.py

[ ... ]

omz

Could it be that you didn't close the tar file after writing to it? That might explain the corrupted file.

charmaex

Thank you ccc I changed the upload to the way you wrote it and the upload seems to work fine now.

Still getting ReadError when downloading the files like this:

download_file(s[0], ziel)
tarfile.open(ziel, 'r:*').extractall('')

The file appears within the folder still not able to untar.

ccc

Here is the other half of the puzzle. It does roughly the opposite of the script above. It reads the tar file from Dropbox and writes a local copy. It then does a tar extractall on that local copy to recreate the original script (!! It will overwrite !!)

tarball_from_dropbox.py

charmaex

Thank you all!
cccs solution works fine :)

ccc

@charmaex, if it works for you the star my repo.