32

I want to use lftp -c to do an entire session in one go (as I'll be launching this from a script later on) and I managed with -e but that ofc leaves me with the interactive session which I don't want.

Manual states

-c commands
          Execute the given commands and exit. Commands can be separated with a semicolon,  `&&'
          or  `||'.  Remember to quote the commands argument properly in the shell.  This option
          must be used alone without other arguments.

But I don't understand how I should quote and string my commands/interactions together correctly.

lftp -e "put -O remote/dir/ /local/file.txt" -u user,pass ftpsite.com works excellent. But I want to exit after executing the command;

lftp -c "open -u user,pass ftpsite.com" || put -O "remote/dir/ /local/file.txt" just shouts at me, or in fact any combination of quotes I tried (|| or && regardless)

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Recct
  • 647
  • 3
  • 8
  • 15

3 Answers3

47
$ lftp -c "open -u user,pass ftpsite.com; put -O remote/dir/ /local/file.txt" 

should do it.

If this doesn't work try adding to your /etc/lftp.conf the following lines:

set ftp:ssl-protect-data true
set ftp:ssl-force true
set ftp:ssl-auth TLS
set ssl:verify-certificate no
slm
  • 363,520
  • 117
  • 767
  • 871
glenn jackman
  • 84,176
  • 15
  • 116
  • 168
  • 2
    is there anyway of making this work if the password has characters in it like `' " : ;` – Pete Jul 12 '16 at 16:39
  • I got tripped up, because I had a space after that first comma, once I figured that out it worked great – patrick Apr 17 '18 at 14:52
20

lftp -e "put -O remote/dir/ /local/file.txt; bye" -u user,pass ftpsite.com

Mohnish
  • 391
  • 3
  • 7
1

lftp -e "put -O remote/dir/ /local/file.txt; bye" ftp.yourhost.com

and put your credentials under ~/.netrc like

machine ftp.yourhost.com login your_username password your_password

Putting passwords in the cli is absolutely no-go since those are even readable when using ps -aux during the upload.. beside the bash history also.

Eugen Mayer
  • 111
  • 4