58

I have a problem when using scp on Linux, it says "not a regular file". I looked at other questions/answers about that, but I can't find out what's wrong... I wrote:

scp aa@aa:/home/pictures/file.fits .

to copy file.fits from aa@aa, /home/pictures to the current directory. I also tried without using /home/, but it didn't work neither...

Do you understand what's wrong?

Markus W Mahlberg
  • 19,711
  • 6
  • 65
  • 89
Fourmicroonde
  • 591
  • 1
  • 4
  • 3
  • 3
    Try: `scp aa@aa:~/pictures/file.fits .` – ryekayo Apr 09 '15 at 19:19
  • 1
    maybe the path is wrong and should contain your Linux user name. /home//pictures maybe? – Zoli Apr 09 '15 at 19:24
  • Tilda will be your best friend in this case :). Don't extend your directory path in this case. And now that I am thinking of it, your command wont work anyways. If you were to add the whole directory, it would look something like: `scp aa@aa:/home/aa/pictures/file.fits .` – ryekayo Apr 09 '15 at 19:26
  • Log in with ssh (`ssh aa@aa`) and give command: `file /home/pictures/file.fits` and tell us what that says. – hyde Apr 09 '15 at 19:27
  • It will save you time and effort just by switching to `rsync`. Use `rsync -azHvu aa@aa:/home/pictures/file.fits .`. This will allow rsync to copy recursively and follow symlinks and show (verbose) what it is copying. – alvits Apr 09 '15 at 20:49
  • if it is a folder try to use ```-r``` flag, it worked on my case. – Nagmat Feb 16 '21 at 06:16
  • ```sudo scp -r -P 4444 folder/ admin@144.15.13.21:~/Downloads``` – Nagmat Feb 16 '21 at 06:22

8 Answers8

103

I just tested this and found at least 3 situations in which scp will return not a regular file:

  1. File is actually a directory
  2. File is a named pipe (a.k.a. FIFO)
  3. File is a device file

Case #1 seems most likely. If you meant to transfer an entire directory structure with scp use the -r option to indicate recursive copy.

Multimedia Mike
  • 12,660
  • 5
  • 46
  • 62
  • 25
    It also occurs if you're not awake yet and you have your source and destination inverted and you're trying to copy a non-existent file from your destination to your source... – BenAlabaster Dec 08 '15 at 03:37
  • 1
    This implies reading stdin and writing stdout as in `sftp -b <(echo get file /dev/fd/1)` – ceving Apr 05 '17 at 09:49
  • 1
    I am facing the issue with symlinks too. – codewandler Nov 01 '17 at 16:32
  • I'm trying to handle second case(in fact, I try to copy physical disk(like `/dev/sda` but actual name is a bit different. possible solution is to pipe disk to fifo then scp it to my host) – quant2016 Oct 20 '22 at 14:58
31

"/home/pictures/file.fits" must name an actual filesystem object on the remote server. If it didn't, scp would have given a different error message.

I see that FITS is an image format. I suppose "/home/pictures/file.fits" is the name of a directory on the remote server, containing FITS files or something like that.

To copy a directory with scp, you have to supply the "-r" flag:

scp -r aa@aa:/home/pictures/file.fits .
Kenster
  • 23,465
  • 21
  • 80
  • 106
  • 7
    This really helped me `To copy a directory with scp, you have to supply the "-r" flag` – wruckie Jan 26 '17 at 19:21
  • This resolved a problem I was having where trying to scp a UTM virtual machine file...or so I thought. .utm is a directory so I needed the '-r'. – Bagels1b Jun 28 '23 at 14:18
10

One way this error can occur is if you have a space before the first path like below:

scp myUserName@HostName: /path/to/file  /path/to/new/file                            ^

To fix, just take the space out:

scp myUserName@HostName:/path/to/file  /path/to/new/file
wizurd
  • 3,541
  • 3
  • 33
  • 50
6

By being teaching lots of people of basic sysadmin I must say in 90% cases it is because they are trying to copy directory without passing -r source

Just use -r flag. E.g to copy from remote to local:

scp -r root@IP:/path/on/server/ /path/on/local/pc
Ivan Borshchov
  • 3,036
  • 5
  • 40
  • 62
4

simple steps you need to follow

1)scp -r user@host:/var/www/html/projectFolder /var/www/html/localsystem-project-folder

2)scp -r user@host:/var/www/html/projectFolder/filename.php /var/www/html/localsystem-project-folder/

here -r is for recursive traverse the director will help you without any error.

niraj rahi
  • 57
  • 1
  • 5
4

It is possible that you are working with a directory/folder.

If this is the case, here is what you want to do:

  1. First, compress the folder. By running the command:

    zip -r name_of_folder.zip name_of_folder

  2. Then use the scp command normally to copy the file to your destination:

    scp path/to/name_of_folder.zip server:localhost:/path/to/name_of_folder.zip

  3. Enter your password if it prompts you for one.

  4. Unzip the name_of_folder.zip with this command:

    unzip name_of_folder.zip

That is it, you now have your folder in the destination system. By the way, this is for zip compression.

NOTE: If you are on Mac OS and you don't want to see resource files such as _MACOSX, you may run:

**zip -r -X name_of_folder.zip name_of_folder**

Meaning the above command should be used instead of that in step 1 above.

Olu Adeyemo
  • 825
  • 9
  • 17
1

You can use the recursive (-r) flag to copy the files.

get -r folderName
-1

It doesn't work because you need the precise the name of copied file ; So use this command like this :

scp aa@aa:/home/pictures/file.fits ./file.fits

You can rename your file too like this :

scp aa@aa:/home/pictures/file.fits ./newNameFile.fits
Necoras
  • 6,743
  • 3
  • 24
  • 45
Faunus
  • 1