When I try to use sftp to transfer a directory containing files, I get an error message:
skipping non-regular file directory_name
The directory contains a couple of files and two subdirectories.
What am I doing wrong?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
scp, requires that when you copy a folder (and its contents, obviously), you have to explicitly tell it you want to transfer the folder recursively with the
-r to the command.
I can only suggest, you use
rsync. It is somewhat of an industry standard, when moving files over secure connections.
rsync -alPvz ./source_dir server.com:destination_dir
It is what I've been using for years by now.
-a option takes care of things like directory recursion)
You may also be able to use use
scp. The general format is
scp -rp sourceDirName username@server:destDirName
scp means "secure copy". The flags are
-rrecurse into subdirectories
-ppreserve modification times
I believe the rest of the items are self-explanatory
This works for me:
1) connect via
sftp to remote host
2) change into the remote directory you wish to copy. (Example: cd Music)
3) change to the local directory you wish to copy stuff to. (Example: lcd Desktop)
4) Issue this command:
get -r *
rsync is not an option, I would next recommend
Then use the
mirror command to recursively upload, like this:
(Note that recursion is the default. The
-R is for reverse — to make the mirror command upload instead of download. Try adding
--dry-run to do a trial to make sure it's doing what you expect.)
Or to upload without recursion:
You have to
cd into the directories you want to mirror. Works great!
If you can, use sshfs. It's a FUSE filesystem, available on most modern unices, and works with any SFTP server. This is a remote filesystem: it allows you to manipulate remote files (over the SFTP protocol) with the usual utilities.
mkdir /mount/point sshfs server.example.com:/remote/path /mount/point ls /mount/point cp -Rp /mount/point/somedir /local/location fusemount -d /mount/point
It's a bit of a kludge but what works for me is to:
sshto login to the remote machine
sftpfrom the remote machine to your local machine
getcommand with the
-roption to move the directory and all of its files.
If you question is actually 'how do I use sftp to transfer a directory', then
sftp -r user@server
But if you transferring a directory, I might suggest two better options, depending on your needs.
sftp requires logging into the remote server in a ssh-like command prompt, but if all you want is the file(s), there are easier and quicker ways.
For a one time transfer, to upload try:
# upload source directory to remote server scp -rp source_dir user@server:dest #download directory from remote server: scp -rp user@server:source_dir dest #specifying ssh key: scp -rp -i ~/.ssh/key user@server:source_dir dest #remote directory has spaces scp -rp -i ~/.ssh/key user@server:"source\\ dir" dest
If you plan on syncing the directories on a regular basis, using rsync makes more sense. It performs deltas between the two directories, saving transfer time and data over the wire.
rsync -r -a -v -e ssh --delete source_dir user@server:dest
Here is a list of some of the most common rsync options: (taken from here)
Hope that helps!
you can get from the server to your local path by
scp -rp user@server:directoryname(full path) .