Repository: conan-io/conan

Issue:
[bug] conan download with optional user/channel does not work
### Summary

Downloading Conan packages without user/channel (i.e. `zlib/1.2.11` instead of `zlib/1.2.11@conan/stable`) does not work. Such packages are built on CCI and it will be good to be able to download them for debugging.

### Environment Details (include every applicable attribute)
  * Operating System+version: macOS 10.14.6
  * Conan version: conan 1.19.3
  * Python version: 3.7.4

### Steps to reproduce (Include if Applicable)

1. Run `conan download 'zlib/1.2.11:76f87539fc90ff313e0b3182641a9bb558a717d2'` to download a package without explicit user/channel
2. Expected: package is downloaded
2. Actual: got the error `ERROR: Provide a valid full reference without wildcards`

### Thoughts

The syntax for a short reference was given from [Conan docs](https://docs.conan.io/en/latest/using_packages/conanfile_txt.html) and from [conan-center-index docs](https://github.com/conan-io/conan-center-index/wiki).

Anyway I tried following commands with the same error:
- `conan download 'zlib/1.2.11@_/_#76f87539fc90ff313e0b3182641a9bb558a717d2'`
- `conan download 'zlib/1.2.11@/:76f87539fc90ff313e0b3182641a9bb558a717d2'`

And this command with a different error "ERROR: Recipe not found: 'zlib/1.2.11'":
- `conan download 'zlib/1.2.11@#76f87539fc90ff313e0b3182641a9bb558a717d2'`

It is curious that if Conan is run with `--package` argument, it suggests to use the exactly failed command:
```conan download --package 76f87539fc90ff313e0b3182641a9bb558a717d2 'zlib/1.2.11'
WARN: Usage of `--package` argument is deprecated. Use a full reference instead: `conan download [...] zlib/1.2.11:76f87539fc90ff313e0b3182641a9bb558a717d2`
ERROR: Provide a valid full reference without wildcards.
```

The same problem with upload command was fixed recently in https://github.com/conan-io/conan/issues/5822.

I suppose the `check_valid_ref` method should relax the requirements for short references..


Discussion:
Reproduced.

Yes, the workaround is to use the deprecated way:

```bash
conan download zlib/1.2.11@ -p 76f87539fc90ff313e0b3182641a9bb558a717d2
```

I am going to check possible fixes

Resolving patch:
diff --git a/conans/client/command.py b/conans/client/command.py
--- a/conans/client/command.py
+++ b/conans/client/command.py
@@ -403,6 +403,8 @@ def download(self, *args):
                                "`conan download [...] {}:{}`".format(reference, packages_list[0]))
         else:
             reference = repr(pref.ref)
+            if pref.ref.user is None:
+                reference += "@"
             packages_list = [pref.id]
             if args.package:
                 raise ConanException("Use a full package reference (preferred) or the `--package`"


Test patch:
diff --git a/conans/test/functional/command/download_test.py b/conans/test/functional/command/download_test.py
--- a/conans/test/functional/command/download_test.py
+++ b/conans/test/functional/command/download_test.py
@@ -3,7 +3,8 @@
 from collections import OrderedDict
 
 from conans.model.ref import ConanFileReference
-from conans.test.utils.tools import TestClient, TestServer, NO_SETTINGS_PACKAGE_ID, TurboTestClient
+from conans.test.utils.tools import (TestClient, TestServer, NO_SETTINGS_PACKAGE_ID, TurboTestClient,
+                                     GenConanfile)
 from conans.util.files import load
 
 
@@ -165,7 +166,7 @@ def test_download_with_full_reference_and_p(self):
                       " command argument, but not both.", client.out)
 
     def test_download_with_package_and_recipe_args(self):
-        client = TestClient();
+        client = TestClient()
         client.run("download eigen/3.3.4@conan/stable --recipe --package fake_id",
                    assert_error=True)
 
@@ -200,3 +201,22 @@ def download_not_found_reference_test(self):
         client = TurboTestClient(servers=servers, users={"default": [("lasote", "mypass")]})
         client.run("download pkg/0.1@lasote/stable", assert_error=True)
         self.assertIn("ERROR: Recipe not found: 'pkg/0.1@lasote/stable'", client.out)
+
+    def no_user_channel_test(self):
+        # https://github.com/conan-io/conan/issues/6009
+        server = TestServer(users={"user": "password"}, write_permissions=[("*/*@*/*", "*")])
+        client = TestClient(servers={"default": server}, users={"default": [("user", "password")]})
+        client.save({"conanfile.py": GenConanfile()})
+        client.run("create . pkg/1.0@")
+        client.run("upload * --all --confirm")
+        client.run("remove * -f")
+
+        client.run("download pkg/1.0:{}".format(NO_SETTINGS_PACKAGE_ID))
+        self.assertIn("pkg/1.0: Downloading pkg/1.0:%s" % NO_SETTINGS_PACKAGE_ID, client.out)
+        self.assertIn("pkg/1.0: Package installed %s" % NO_SETTINGS_PACKAGE_ID, client.out)
+
+        # All
+        client.run("remove * -f")
+        client.run("download pkg/1.0@")
+        self.assertIn("pkg/1.0: Downloading pkg/1.0:%s" % NO_SETTINGS_PACKAGE_ID, client.out)
+        self.assertIn("pkg/1.0: Package installed %s" % NO_SETTINGS_PACKAGE_ID, client.out)