meganz / MEGAcmd

Command Line Interactive and Scriptable Application to access MEGA
Other
1.89k stars 406 forks source link

Can't upload file with spaces in path on Windows #972

Open LunarTulip opened 2 months ago

LunarTulip commented 2 months ago

This morning, I installed MEGAcmd, added its directory-of-batch-files to my path, and set about trying to upload some files.

It works fine when neither the files' paths nor their destinations' paths contain spaces. mega-put.bat Test.txt Target_Remote_Directory, for example, works fine.

However, if either the file's path or its destination's path does contain a space—mega-put.bat "Test With Space.txt" Target_Remote_Directory or mega-put.bat Test.txt "Target Remote Directory"—then I get the following error:

'C:\Users\Lunar' is not recognized as an internal or external command,
operable program or batch file.

...and I get this error even when the file I'm trying to upload isn't on drive C at all.

(My personal folder name contains a space. It's not ideal; I'd have changed it years ago if changing one's personal folder name were more practical than it in fact is, but it isn't, so I haven't. I'm guessing that's related to the root cause somehow, but I have little idea of the details.)

This seems like probably not intended behavior! And, to whatever extent workarounds exist, I've thus far failed to find them.

LunarTulip commented 2 months ago

Update: found a workaround.

Specifically: instead of running mega-put.bat, run MEGAclient.exe put. This avoids a layer of indirection through the batch script, which removes whatever un-quoting effect was causing the prior problem.

(Then, second, cd into the directory with the file before uploading, and upload via relative path, in order to avoid some I-think-mostly-unrelated error which looks like this:

[API:err: 19:55:50] Unable to open local path: \\?\G:/Backup/Backups Overflow/Tumblr/169 (2024-05-03).7z

...as arises if I try to upload that path, even directly via the MEGAclient executable, while my working directory is on a different drive. But that seems like an unrelated issue I just happened to run into at the same time, rather than part of the same problem.)