Scp ошибка not a regular file

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's user avatar

asked Apr 9, 2015 at 19:18

Fourmicroonde's user avatar

7

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.

answered Apr 9, 2015 at 20:11

Multimedia Mike's user avatar

Multimedia MikeMultimedia Mike

12.7k5 gold badges46 silver badges62 bronze badges

4

«/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 .

answered Apr 9, 2015 at 20:15

Kenster's user avatar

KensterKenster

23.5k21 gold badges81 silver badges106 bronze badges

2

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

answered Sep 3, 2015 at 22:32

wizurd's user avatar

wizurdwizurd

3,5513 gold badges33 silver badges50 bronze badges

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

answered May 15, 2021 at 21:24

Ivan Borshchov's user avatar

Ivan BorshchovIvan Borshchov

3,0455 gold badges40 silver badges62 bronze badges

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.

answered Feb 19, 2019 at 7:19

niraj rahi's user avatar

niraj rahiniraj rahi

571 silver badge5 bronze badges

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.

answered Sep 14, 2019 at 3:01

Olu Adeyemo's user avatar

Olu AdeyemoOlu Adeyemo

8259 silver badges17 bronze badges

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

get -r folderName

answered Dec 29, 2021 at 12:12

Alagie F. Nget's user avatar

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's user avatar

Necoras

6,7833 gold badges24 silver badges45 bronze badges

answered Jun 9, 2017 at 21:00

Faunus's user avatar

1

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's user avatar

asked Apr 9, 2015 at 19:18

Fourmicroonde's user avatar

7

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.

answered Apr 9, 2015 at 20:11

Multimedia Mike's user avatar

Multimedia MikeMultimedia Mike

12.7k5 gold badges46 silver badges62 bronze badges

4

«/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 .

answered Apr 9, 2015 at 20:15

Kenster's user avatar

KensterKenster

23.5k21 gold badges81 silver badges106 bronze badges

2

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

answered Sep 3, 2015 at 22:32

wizurd's user avatar

wizurdwizurd

3,5513 gold badges33 silver badges50 bronze badges

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

answered May 15, 2021 at 21:24

Ivan Borshchov's user avatar

Ivan BorshchovIvan Borshchov

3,0455 gold badges40 silver badges62 bronze badges

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.

answered Feb 19, 2019 at 7:19

niraj rahi's user avatar

niraj rahiniraj rahi

571 silver badge5 bronze badges

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.

answered Sep 14, 2019 at 3:01

Olu Adeyemo's user avatar

Olu AdeyemoOlu Adeyemo

8259 silver badges17 bronze badges

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

get -r folderName

answered Dec 29, 2021 at 12:12

Alagie F. Nget's user avatar

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's user avatar

Necoras

6,7833 gold badges24 silver badges45 bronze badges

answered Jun 9, 2017 at 21:00

Faunus's user avatar

1

A regular file is a file that isn’t a directory or more exotic kinds of “special” files such as named pipes, devices, sockets, doors, etc. Symbolic links are not regular files either, but they behave like their target when it an application is accessing the content of the file.

You passed root@IP: as the source of the copy and /path/to/picture.jpg as the destination. The source is the home directory of the user root on the machine IP. This is useful as a destination, but not as a source. What you typed required to copy a directory onto a file; scp cannot copy a directory unless you ask for a recursive copy with the -r option (and it would refuse to overwrite an existing file with a directory even with -r, but it would quietly overwrite a regular file if the source was a regular file).

If /path/to/picture.jpg is the path on the remote machine of the file you want to copy, you need to stick the file name to the host specification. It’s the colon : that separates the host name from the remote path. You’ll need to specify a destination as well.

scp root@IP:/path/to/picture.jpg /some/destination

If you want to copy the local file /path/to/picture.jpg to the remote host, you need to swap the arguments. Unix copy commands put the source(s) first and the destination last.

scp /path/to/picture.jpg root@IP:

If you want to copy the remote file /path/to/picture.jpg to the same location locally, you need to repeat the path. You can have your shell does the work of repeating for you (less typing, less readability).

scp root@IP:/path/to/picture.jpg /path/to/picture.jpg
scp {root@IP:,}/path/to/picture.jpg

The SCP (Secure. Contain and protect) utility is used for copying the files in the system over the network. It copies the files/directories locally such as from one directory to another or to the remote hosts or in between the two remote hosts. While copying the files from any host to the computer, you may face the error “scp: not a regular file” because the syntax is not being followed properly.

This post will describe the reasons and solutions for the error “scp: not a regular file”.

  • Reason: Source Path Not Specified
  • Solution: Specify the Source Path and Copy the File Recursively

Reason: Source Path Not Specified

The reason for this error is that the user has provided the “root@IP:” as the source file, i.e., the user home directory. The users can give the home directory as a destination but not as a source file. 

The following snippet shows an error, where the source path is not specified: 

$ scp Henry@ubuntu: /home/itslinuxfoss/file.txt

Solution: Specify the Source Path and Copy the Files Recursively

The solution for this error is that, use the below syntax for copying the files:

$ scp -r root@IP/Hostname:/path/to/file /path/to/filedestination

Write the “scp”, “r” flag for recursively copying the files, and type the hostname/IP with the source path to the file. Then, type the destination path where the file will be placed.

Example: 

The below command will copy the “file.txt” file from the “information” directory of the remote host “Henry@ubuntu”. Then paste it into the “example” directory of the current machine:

$ sudo scp -r Henry@ubuntu:information/file.txt /example

The file from the remote host has been copied successfully

Conclusion

The reason for the error “scp: not a regular file” is that the source path is not specified while copying the file. To fix this error, use the correct syntax of the “scp” command, specify the source path, and copy the file recursively. 

This post has covered the reason and the solution for the error “scp: not a regular file”.

The error message ‘scp not a regular file’ indicates that you are attempting to use the SCP command to copy a file, but the specified source or destination is not a regular file. The SCP command is widely used to securely transfer files between hosts over SSH (Secure Shell) connections. It requires specifying both the source and destination for the file transfer. Therefore, the error usually occurs due to an incorrect file path.

The error message “scp not a regular file” can occur on various operating systems, including Unix-like systems such as ‘Linux’, ‘macOS’, and ‘BSD’. It can also occur on Windows systems that have the SCP command installed, typically as part of third-party software like ‘PuTTY’ or ‘Cygwin’

To assist you in resolving this error, we have curated a troubleshooting guide that will help you address this issue in detail.

1. Syntax issues

Unix and Linux have a reputation for strict adherence to well-defined syntax rules and standards governing commands, shell scripting, and configuration files. Following the prescribed syntax is crucial to ensure proper execution and expected behavior in these operating systems.

So, if an imperfection in the syntax is discovered, the system automatically prompts the user with an error; in this case, the error is “scp: not a regular file.” There are a number of considerations one should keep in mind when trying to copy a file.

1.1 Check Spaces

Checking for spaces in file or directory names is an important task in Unix/Linux. It ensures that there are no leading or trailing spaces that could potentially cause issues when working with commands or scripts.

For instance, let’s consider a scenario in which you have a file named ‘my_file.txt’ located in the ‘/home/user’ directory. To verify the presence of spaces in the file name, you can use the following command:

ls -Q/home/user

The -Q option is employed to display file and directory names within quotes. If any spaces exist in the file name, they will be visibly enclosed within the quotes upon running this command.

For instance, if the output shows a particular result, we should take the necessary action

"myfile.txt"

It signifies the presence of a space in the file name. In such cases, it is recommended to handle spaces in file names by using special characters or enclosing the name in quotes when working with commands or scripts.

To prevent potential issues associated with spaces in file or directory names, it is generally advisable to use filenames that do not contain spaces

1.2 Missing or extra colon

The SCP command requires the use of colons to specify the remote server and file paths. For example, using incorrect syntax like ‘scp user@host filepath’ instead of ‘scp user@host:filepath’ can cause an error. So, in order to avoid the error “scp not a regular file,” make sure that you adhere to the syntax limitations.

1.3 Mixing up Source and Destination

When using the SCP command, mixing up the source and destination paths can cause errors or unexpected behavior. It is important to maintain the correct order to ensure a successful file transfer.

To clarify, the SCP command follows the syntax:

scp <source> <destination>.

If you mistakenly swap the source and destination paths, it may lead to files being copied in the wrong direction or trigger the “scp not a regular file” error if the destination is invalid.

For instance, let’s consider copying a file named “file.txt” from the local machine to a remote server:

Correct: scp file.txt user@remote:/path/to/destination
Incorrect: scp user@remote:/path/to/destination file.txt

The incorrect usage would attempt to copy the remote file named “file.txt” to the local machine, resulting in undesired outcomes or an error. To ensure smooth file transfers, always double-check and maintain the correct order of the source and destination paths when using the SCP command.

2. Use the option “-r”

The reason you’re facing this error is that you’re probably copying a directory while not specifying to the operating system that you’re copying a directory.

By default SCP treats the file as regular files, so option -r must be added when copying a directory. The error “scp not a regular” occurs when the user is trying to copy a directory and does not specify this action by using the -r option.

When you want to copy an entire directory, along with all its subdirectories and files, you would use the “-r” option. Without the “-r” option, SCP would only copy individual files, not directories.

Here’s an example usage of scp with the “-r” option:

scp -r /path/to/source_directory user@remote:/path/to/destination_directory

This command would recursively copy the contents of the “source_directory” and all its subdirectories to the “destination_directory” on the remote server.

Photo of Dawood Janjua

Dawood Janjua

Dawood Janjua is a highly skilled technology enthusiast with a wealth of knowledge in Windows troubleshooting and gaming. He holds a CCNA certification and has a proven track record of providing exceptional support to customers. While currently working as an author, Dawood aspires to obtain the prestigious CCIE certification in the future to expand his technical expertise and provide regional-level support. With his passion for gaming and expertise in technology, Dawood is committed to sharing his knowledge with the community to help others improve their skills and knowledge in the field.

Понравилась статья? Поделить с друзьями:
  • Scp ошибка ford
  • Sc553 00 ricoh ошибка
  • Scp virtual bus driver ошибка 52
  • Sc551 00 ricoh ошибка
  • Scp toolkit ошибка