2

been having problems all day with this single scp command. Been searching and asking people etc etc.

$ scp -P portNumber /ReferenceFiles/CompanyA,The/Some\ DirectoryWithA\ Space/Game user@server:/ReferenceFiles/CompanyA/Game

I tried to do a file within the directory, but get file does not exists, and if I try to do the scp command on the directory I get "not a regular file".

I have tried using double back slashes for the spaces, using single and double quotes. I'm really new to this and have been thrown in expecting to know this stuff when I was told I would be doing mostly PHP and Flash...

Any help or suggestions welcome.

Thanks

2
  • worked a way round this by moving the content of the folder to a temp folder first, but still, want/need to understand what I was doing wrong. It should work, and it didn't and that frustrates me. I want to learn! =] Aug 5 '10 at 15:08
  • The folders have spaces and commas in them, as my example shows by saying Some Directory With A Space Aug 6 '10 at 8:43
1

One of the easiest ways to get around character escaping on the command-line (if that's the cause of the problem) is to use tab-completion to let it fill in the "awkward" characters; depending on how full your /ReferenceFiles directory is, you might be able to do something like

  scp -P portNumber /Ref<tab>CompanyA<tab>Some<tab>Game/file user@server:...

Alternately, you can use a ? instead of a character, provided there aren't going to be too many conflicting file/directory names:

 scp -P portNumber /ReferenceFiles/CompanyA,The/Some?DirectoryWithA?Space/Game/file ...

For directories, you need to use the -r option to scp (its omission is why you got the "not a regular file" error).

Lastly, could it be that the destination on the server doesn't exist as typed, and that's the source of the error (and not the source file)?

5
  • Thanks for your answer. Tab doesn't work with scp. Correct I understand I should have used the -r flag. Still, when I tried to do an exact file, it said it couldnt be found, and yet I could go directly to that directory and see it there... Aug 5 '10 at 14:46
  • @Relequestual: tab completion is a function of the shell you are using. If you aren't using bash, then the rules may vary slightly, but if you are using bash, and there isn't ambiguity, then you should be able to use tab to complete local-side file/directory names. Aug 5 '10 at 15:06
  • @Micheal: I honestly don't know. Our server guy said if I used zsh then it would do tab completion, and it did, so as to why it didn't before I'm not sure. Aug 5 '10 at 15:11
  • @Relequestual likely the advanced bash-completion broke stuff, with different commands it should have worked as bahs auto-completes filenames by default only. When the tab completion stops, press TAB again to get a list of suggestions
    – vdboor
    Aug 5 '10 at 15:55
  • @Micheal Right you are. Of course I already knew about double tabbing to get a list of suggestions. Thanks for the help Aug 5 '10 at 16:07
1

Standard shell escapes should suffice, so including the comma:

scp -P portNumber /ReferenceFiles/CompanyA\,The/Some\ DirectoryWithA\ Space/Game user@server:/ReferenceFiles/CompanyA/Game

3
  • Also tried that. Thanks though. Aug 5 '10 at 14:48
  • And it didn't work? There are serveral ways to cheat here... you could create a symlink to "Some DirectoryWithA Space" to access the 'Game' directory without the odd symbols. Or you could chdir (cd) to there and use a relative indicator (like ./Game) to copy it out.
    – Joris
    Aug 5 '10 at 14:53
  • Sadly not. worked a way round it, got moved to a temp directory at the remote servers end (was sshing to it which is why it was from local). Just need to understand what I was doing wrong with that command. Aug 5 '10 at 15:00
1

You have to use both \ escaping and quotes :

scp -o port=portNumber "/ReferenceFiles/CompanyA,The/Some\ DirectoryWithA\ Space/Game" user@server:/ReferenceFiles/CompanyA/Game

Don't ask me why, but it works.

4
  • No joy for me sadly. =[ it just tells me the usage details. I think it understand I'm confused. Aug 5 '10 at 14:58
  • also use -o port=PORTNUMBER, instead of -p. Only include one path in quotes. I corrected my answer to reflect this.
    – Jasper
    Aug 5 '10 at 15:26
  • 1
    You shouldn't have to use both quotes, and escaping the space with a \. The whole point of the quotes, is that the shell sends the entire filename as a single argument to the scp process. The same applies to the backslaces. With both combined, you literally send a backslash with space to the command.
    – vdboor
    Aug 5 '10 at 15:52
  • A "little" late comment but… it seems that scp uses a shell at the other end, so you must escape characters for your local shell and once again for the remote one. Sep 10 '14 at 19:51
1

Your command works for me; is that really the command that gave you trouble, as opposed to going the other way? scp has no trouble with local file names, but the remote file names undergo shell expansion on the remote side. So if you're typing the scp command in a shell, you need to quote remote file names twice. An easy way if the name doesn't contain any single quotes is to protect special characters with \ and then put single quotes around the argument, as in

scp -P portNumber user@server:'/ReferenceFiles/CompanyA,The/Some\ DirectoryWithA\ Space/Game' /ReferenceFiles/CompanyA/Game

The same applies to rsync, by the way.

0

Assuming that "Game" is a directory, to copy all files inside a given directory with scp, simply use the -r (recursive) option with a directory as the target. Additionally, the target is the name of the parent of Game on the remote, hence you can drop "Game" from the remote argument. Also you need to escape that comma.

E.g.

$ scp -r -P portNumber /ReferenceFiles/CompanyA\,The/Some\ DirectoryWithA\ Space/Game user@server:/ReferenceFiles/CompanyA
1
  • Yup realised that. Sadly no luck with that either. Tried it with an individual file too but it said the directory didn't exists, when it clearly did. Thanks though =] Aug 5 '10 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.