Giter VIP home page Giter VIP logo

onedrive-cli's Introduction

onedrive-cli

Cross-platform command line interface for OneDrive (Personal)

Development

The provided shell.nix for the Nix package manager contains all development dependencies. Use it with nix-shell or Direnv's use nix.

Update Nix files

node2nix -l package-lock.json

Installation

From source:

$ git clone https://github.com/lionello/onedrive-cli.git
$ cd onedrive-cli
$ npm install
$ bin/onedrive login

Or use npm:

npm install @lionello/onedrive-cli

Or use nix-env:

nix-env -if https://github.com/lionello/onedrive-cli/archive/master.tar.gz -A package

Usage

usage: onedrive COMMAND [arguments]

This little utility supports the following commands:

  • cat - dumps the contents of a file to stdout
  • chmod - change sharing permissions
  • cp - copies local file(s) to OneDrive or vice-versa
  • df - shows OneDrive storage usage stats
  • find - find file(s) or folder(s) by name, optionally separated by NUL
  • help - shows list of supported commands
  • ln - create a link to the remote item
  • login - request/store an OAuth access token
  • ls - list the contents of a folder
  • mkdir - create a remote folder
  • mv - move a local file to OneDrive or vice-versa
  • rm - delete a file from OneDrive (not implemented)
  • sendmail - send an invitation email for editing to recipients
  • stat - dump all information for particular file(s)
  • wget - copy a remote URL to OneDrive (server side)

Examples

List the contents of the Public folder

onedrive ls Public

Grep one file

onedrive cat Documents/passwords | grep boa

Let OneDrive upload a file server side

onedrive wget http://mega.com/somehugepublicfile Documents/somehugepublicfile

Upload files recursively

find * -type f -print0 | xargs -0 -n1 -I{} onedrive cp "./{}" "Shared Favorites/{}"

Move remote files to a new folder

onedrive find 'Pictures/Camera Roll' -regex 2015 -type f -print0 | xargs -0 onedrive mv -t :/Pictures/2015/

FAQ

Access token was not found; 'login' first.

The onedrive utility needs an access token in order to read/write to your OneDrive storage. Use theonedrive login command to get the address of the Microsoft login page. After login, this page will redirect to the file oauthcallbackhandler.html (https://github.com/lionello/onedrive-cli/blob/master/docs/oauthcallbackhandler.html) and extract the access_token from the URL parameters. Copy-paste this token into the command line. This will save the token in a file called ~/.onedrive-cli-token. These tokens have a validity of 1 hour.

"An item with the same name already exists under the parent"

Currently, a copy will fail if a file with the same it already exists. Change the name of the target, or use other means to delete/rename the existing file in your OneDrive.

Invalid source name

You cannot copy folders. Specify a source file instead, or use wildcards.

Invalid target name

The target file name cannot be determined from the source path. Specify a target file name.

Use ./ or :/ path prefix for local or remote paths.

The cp command supports both local->remote as well as remote->local copy. To make it clear which path is remote and which is local, either use ./ as a prefix for the local path, or use :/ as a prefix for the remote path. Either one will suffice.

chmod: Invalid file mode

The chmod command currently only supports -w or -rw. The former tried to downgrade write shares to read-only, whereas the latter removes all shares for the given item(s). Octal modes are accepted (for example 644, 0700) as well as og-rw or g-w.

TODO

  • Implement rm
  • Support gzip/deflate encoding for downloads
  • Uploads larger than 100MiB are not yet supported (needs range API)
  • Support OneDrive for Business
  • Ability to get the link for a file
  • Skip upload/download if the SHA1 matches
  • Adding write permissions (+w) to existing share links

DONE

onedrive-cli's People

Contributors

dependabot[bot] avatar derenix avatar lionello avatar msiemens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

onedrive-cli's Issues

Business support

What is needed for business support? I am very interested in contributing to this project especially if business support can be added.

cp -R fails

Trying to copy a directory recursively fails with this error:

onedrive-cli cp -R Documents .
GET /drive/root:/-R:/children
That item seems to be missing. Someone may have deleted or moved the item, or you may not have permission to view it.

Seems like -R is passed as a folder here:

onedrive-cli/bin/onedrive

Lines 458 to 471 in 5deafe3

if (args[0] === '-t') {
const directory = args[1]
return cp_mv(COPY, args.slice(2), directory)
}
const target = args.pop()
if (args[0] !== '-R') {
return cp_mv(COPY, args, target)
}
// Recursive copy
for (const folder of args) {
await cp_paged(sanitize(folder) + '/children', target)
}

Here, args has the following value before being iterated: [ '-R', 'Documents', '.' ]

If I remove the first argument before doing the recursive copy, everything works fine.

Question about "Ability to get the link for a file"

Really looking forward to "Ability to get the link for a file"

Glad you started this project as I just came across an issue of mine that requires such ability to overcome it. I would love to help but I'm afraid I'm not that well versed in JS

My question is how you envision such capability ?
Will it just give the file's URL starting from a relative path to that file as input and it looks it up on the OneDrive cloud storage, OR could it compute such path starting from a local file saved on the computer inside the OneDrive sync folder.

My doubt is on the second part as I don't know how NodeJS can access local system files.

Unable to list contents of a shared folder

Hey,
awesome tool

I wanted to ls a folder that is shared with me but I'm not an owner of. I can stat it but ls returns 0 children even though that folder is full.

Let me know if you need more info about how to reproduce this.

I think it's a bug.

overwrite existing files

Problem:
onedrive-cli cp ./source Destination/ reports "An item with the same name already exists under the parent"
This is correct, but I cannot find a way to override the default behavior to allow me to overwrite an existing file. It seems like "name.conflictBehavior=fail" is hard-coded into the operation. Any plans for arguments to the cp command that would allow other behaviors?

sintax incorrect

install guide incorrect.

The correct sintax is with the "./" .
**./**onedrive COMMAND [arguments] and not onedrive COMMAND [arguments]

Cannot cp or wget

I've got a local directory with 6000+ files that I'm trying to push to onedrive.

Here is what I run:

find "/Volumes/Transcend/ar.aymanswoaid" -type f -print0 | xargs -0 -n1 -I{} bin/onedrive mv "{}" ":/Public/Al Quran/audio/uncompressed/audio/64/ar.aymanswoaid/{}"

The output and response I get is:

PUT /drive/root:/Public/Al Quran/audio/uncompressed/audio/64/ar.aymanswoaid//Volumes/Transcend/ar.aymanswoaid/1.mp3:/[email protected]=fail

503 - "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta content='text/html; charset=utf-8' http-equiv='content-type'/><style type='text/css'>body {font-family:Arial; margin-left:40px; }img  { border:0 none; }#content { margin-left: auto; margin-right: auto }#message h2 { font-size: 20px; font-weight: normal; color: #000000; margin: 34px 0px 0px 0px }#message p  { font-size: 13px; color: #000000; margin: 7px 0px 0px0px}#errorref { font-size: 11px; color: #737373; margin-top: 41px }</style><title>OneDrive</title></head><body><div id='content'><div id='message'><h2>Our services aren't available right now</h2><p>We're working to restore all services as soon as possible. Please check back soon.</p></div><div id='errorref'><span>Ref A: 75034D9D7F144C7A8A86ED142DA90339 Ref B: LON21EDGE0908 Ref C: 2019-09-15T12:20:18Z</span></div></div></body></html>"

This (https://stackoverflow.com/questions/52064678/microsoft-graph-api-for-onedrive-responds-with-service-not-available) may give us a clue, but they report a 400 and we get a 503.

I can't even wget the files. Here is the wget I run for just 1 file:

bin/onedrive wget http://cdn.islamic.network/quran/audio/64/ar.aymanswoaid/1.mp3 ":/Public/Al Quran/audio/uncompressed/audio/64/ar.aymanswoaid/1.mp3"

The output and response I get is:

POST /drive/root:/Public/Al Quran/audio/uncompressed/audio/64/ar.aymanswoaid:/children

400 - {"error":{"code":"invalidRequest","message":"[child] An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected."}}

So this time it's a 400.

Any thoughts or ideas?

Thank you - this client looks very promising - it's like s3cmd for OneDrive.

cannot cp to remote side

I tried to copy file to the remote side
onedrive cp backup.tgr.gz :/backup/

but it return an error
PUT /drive/root:/backup/backup.tgr.gz:/[email protected]=fail
Array buffer allocation failed

Any thoughts or ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.