2

I would like to use lftp to put a file in a remote directory and exit in one command. Following the top answer to this question about this very task, I tried the following:

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

I received the following error:

put: Login failed: 530 Box: Invalid user credentials.

I tried the second answer

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

and received the same error.

Doing everything step-by-step worked perfectly, i.e.,

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

but I have to do this for many files. I would like to be able to do this in one command to run it as part of a script. Any tips on how to fix this error, or where to look/start?

duckmayr
  • 123
  • 1
  • 1
  • 5

1 Answers1

3

I use lftp in most of my scripts to automate uploads/downloads and using HEREDOC syntax has always worked:

 lftp -u user,pass ftpsite.com << EOF
 cd remote/dir/ 
 put /local/file.txt
 bye
 EOF

Make sure you protect your password between ' as it may contain reserved characters which get interpreted by the shell (and then not correctly passed to lftp): lftp -u user,'password'.

Daniele Santi
  • 4,127
  • 2
  • 29
  • 30
  • The result was `Unknown command \`-u'.` – duckmayr Sep 18 '18 at 12:10
  • @duckmayr sorry, the `-c` wasn't meant to be there. I've edited my answer. – Daniele Santi Sep 18 '18 at 12:11
  • Thanks for the edit; that fixed the `Unknown command` issue, but I still get the `Login failed error`. I suspect it has to do with some kind of system/`lftp` setting, but I don't know enough about `lftp` to know really where to look. – duckmayr Sep 18 '18 at 12:14
  • @duckmayr It _might_ be that your password has some reserved character(s) which get interpreted by bash, for example `#` or `'` or `"` ? If thats the case, try enclosing password between `'`. – Daniele Santi Sep 18 '18 at 12:20
  • Thanks! I had the `lftp ftpsite.com -u user,pass` in my history with the password between `'`, but didn't make sure the password was between `'` when trying out the command version. Upvoted, will accept if you edit to include the bit about passwords and reserved characters (since that's technically what resolved the problem). Thanks again! – duckmayr Sep 18 '18 at 12:31