Solved Scp wildcard not working on my FreeBSD

Hi all,

I'm really embarassed to ask this questions, but I tried every known (googled) solution which didn't work on my FreeBSD installation
Code:
[root@pha /]# uname -a
FreeBSD pha.xxx.xxx 10.0-RELEASE-p9 FreeBSD 10.0-RELEASE-p9 #0: Mon Sep 15 14:35:52 UTC 2014     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64
I cannot get the wildcard in scp working:
Code:
[root@pha /]# scp -i scp_dsa scp@192.168.0.1:/file.rsc ./scp/
file.rsc                                                        100%   34KB  33.6KB/s   00:00
[root@pha /]# scp -i scp_dsa scp@192.168.0.1:/file.backup ./scp/
file.backup                                                  100%  470KB 470.3KB/s   00:00
[root@pha /]# scp -i scp_dsa scp@192.168.0.1:/file.* ./scp/
scp error: /file.*: no such file or directory!
[root@pha /]# scp -i scp_dsa scp@192.168.0.1:/file.\* ./scp/
scp error: /file.*: no such file or directory!
[root@pha /]# scp -i scp_dsa 'scp@192.168.0.1:/file.\*' ./scp/
scp error: /file.*: no such file or directory!
[root@pha /]# scp -i scp_dsa scp@'192.168.0.1:/file.\*' ./scp/
scp error: /file.*: no such file or directory!
[root@pha /]# scp -i scp_dsa "scp@192.168.0.1:/file.*" ./scp/
scp error: /file.*: no such file or directory!
[root@pha /]# scp -i scp_dsa "scp@192.168.0.1:/file.\*" ./scp/
scp error: /file.*: no such file or directory!

Am I missing any other combination?

Many thanks
 
There is more than one way, but the local shell has to be prevented from interpreting the star. I usually use a backslash:
scp user@remotehost:/file.\* localdestination

That form is shown in one of your tests, which makes me wonder if the files are not located in the root of the remote system. The path does not default to the user's home directory. If that is needed, the tilde must be included:
scp user@remotehost:[B]~[/B]/file.\* localdestination
 
Thanks for a quick reply, unfortunately blocking the shell with backslash doesn't work. The path is correct, the remote system is a Mikrotik router...
 
Looking at the error, from my understanding, the shell is trying to expand "/file.*" when it should be trying to expand "file.*". You could also try # scp -i scp_dsa scp@192.168.0.1:file.\* ./scp/ or # scp -i scp_dsa 'scp@192.168.0.1:file.*' ./scp/, which would assume the root directory I think. My apologies if this is incorrect.
 
Does ssh -i scp_dsa scp@192.168.0.1 ls /file.\* show the files?
This gives me the list of all files in root, just like if you would do (as I told already the remote system isn't exactly UNIX like)
ssh -i scp_dsa scp@192.168.0.1 ls
Looking at the error, from my understanding, the shell is trying to expand "/file.*" when it should be trying to expand "file.*". You could also try # scp -i scp_dsa scp@192.168.0.1:file.\* ./scp/ or # scp -i scp_dsa 'scp@192.168.0.1:file.*' ./scp/, which would assume the root directory I think. My apologies if this is incorrect.
Yep you're right, it assumes root:
Code:
[root@pha /]# scp -i scp_dsa scp@192.168.0.1:file.\* ./scp/
scp error: /file.*: no such file or directory!
 
So it's a question of figuring out what to give the remote shell for a pattern match. If the files have a uniform extension, maybe a pattern with ? to match each character in the extension would work.

Or use ssh ... ls to get a list of all the remote files, filter it locally, and then fetch each file by name with scp.
 
Well the situation is following - I have a working script running on Windows using pscp and * wildcard. I was trying to migrate this backup script to FreeBSD. I need to backup 2 files (from each router on my network) with same name (=hostname) and different extension - therefore I was trying to avoid to script every file using a single command. But if there's no other way around...
 
If the command is running in a script, it might need double escapes. Use scp@192.168.0.1:file.\\*, for example. sh(1) loves to eat escapes and whitespace.
 
Nope, I sometimes think I already tried all possible combinations :)

BTW just tried the command from a Linux box (Debian) and it behaves the same.
 
FreeBSD->FreeBSD the following syntax works (/bin/tcsh is the shell on both sides):
scp 10.100.102.2:"/tmp/*" /tmp/
scp "10.100.102.2:/tmp/*" /tmp/

I'm thinking you get what you pay for with cheap routers. If it's not the cheesy SSH server as wblock@ mentioned, it could easily be whatever embedded shell being used that doesn't support file name globbing.
 
FYI it's definitely a problem of the router OS or SSH server on the router - just tried scp with escape+wildcard between FreeBSD and Debian and it works both ways as expected.

Sorry for bothering you with the question here - now I'm going to re-route this question to Mikrotik forum.

Thanks anyway.
 
Back
Top