14

Command-line sftp in my Ubuntu doesn't have recursive put implemented. I found some debate from 2004 about implementing such feature with -R option switch. So I see some sort of self-made recursion as only option.

Ie.

  • iterate through directory listing
  • cd into directories
  • mkdir them if nonexistent
  • put files

I'm planning on doing this with bash, but any other language would suffice.

Rsync or scp is not an option because I don't have shell access to server. Only sftp.

2
  • 1
    look at my answer for the solution using lftp
    – Ilia K.
    Oct 11, 2010 at 9:55
  • why is shell access necessary for scp?
    – user102008
    Jun 29, 2011 at 20:02

10 Answers 10

16

Look at lftp. It's a powerful file transfer client which supports ftp, ftps, http, https, hftp, fish (file transfer over ssh shell session) and sftp. It has ftp-like interactive interface, but also allows to specify all commands at the command line. Look at mput (non recursive but handles glob patterns) and mirror (poor man's rsync) commands.

I use it with a server which only handles sftp uploads like this:

lftp -c "open -u $MYUSER,$MYPASSWORD sftp://$TARGET ; mirror -R $SOME_DIRECTORY"
1
  • Thanks, lftp seems to do the job. Luckily I don't have the same constraints I had back in '09 :) Oct 8, 2012 at 11:18
4

While I think lftp is the best option if it's available, I got stuck on an ancient install of Cent OS and needed to do a recursive put via SFTP only. Here's what I did:

find dir -type d -exec echo 'mkdir {}' \; | sftp user@host
find dir -type f -exec echo 'put {} {}' \; | sftp user@host

So basically make sure all the directories exist and then send the files over.

3

my ubuntu 12.04 comes with put -r in sftp

2

The GUI FTP client FileZilla also supports SFTP and also supports uploading and downloading while directories.

1

On the command line you can do that by using the putty-tools package. It comes with a sftp replacement called psftp.

It supports mput -r which copies a local directory to the remote recursively.

0

I guess you can do this with bash but it's going to be a lot of work. Instead, I suggest to have a look at Python and the Chilkat library.

0

In Java, you can use edtFTPj/PRO, our commercial product, to transfer recursively via SFTP. Alternatively you might want to consider SCP - that generally supports recursion and runs over SSH.

0

How about sshfs?

Combined, of course, with cp -r.

Or, failing that, rsync -r by itself.

2
  • Quote from the question: "Rsync or scp is not an option because I don't have shell access to server. Only sftp." Sshfs requires ssh access and I only have sftp. Apr 6, 2010 at 14:01
  • Huh. I've never heard of having sftp access without ssh access, so I guess my brain ignored that part. You could still try sshfs. I don't actually know whether it works by ssh or sftp. If you're using GNOME or KDE, you can just type sftp paths into their respective file browsers. Apr 6, 2010 at 17:04
0

After lot's of googling and good answers I used Transmit syncing for the job. Not a very good solution, but does the job.

0

Here is how --

sftp -r  <host>
password:  <pass>

cd <remote dir>     # moves to remote dest dir

put -r localdir/*   # creates dir and copies files over

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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