Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement recursive put in sftp

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.

like image 646
aarreoskari Avatar asked Oct 20 '09 15:10

aarreoskari


1 Answers

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"
like image 120
Ilia K. Avatar answered Oct 09 '22 14:10

Ilia K.