Simple command to connect to FTPS server on Linux command line

17

6

I have an FTP and FTPS server where I can connect to easily with FileZilla. I'm looking for a linux CLI method. I thought lftp does it, but it seems weird. Is there another way?

Here is the method I found on Google to connect to my FTPS with lftp. But I hope there is an easier way:

lftp -c 'open -e "set ftps:initial-prot ""; \
   set ftp:ssl-force true; \
   set ftp:ssl-protect-data true; \
   put test.txt; " \
   -u "USERNAME","PASSWORD" \
   ftps://HOSTNAME:990 '

The code I got above looks like it will fail – haven't tried it yet as I don't like it, I know that the \ need to be at the end of the line.

I'm looking for a much simpler one liner. Here is how I connect from any FileZilla client and it works:

ftps://username:password@ftp.server.com/

Also, this works:

ftps://username:password@ftp.server.com/

user240137

Posted 2013-07-23T16:29:23.483

Reputation: 171

You should probably separate this into two different questions, since they really are. – Taegost – 2013-07-23T16:50:00.913

Please read: How do I format my posts using Markdown or HTML?.

– slhck – 2013-07-23T18:01:23.560

Answers

10

I don't know whether this wasn't available on the 2013 version of lftp, but now you can simply do:

lftp -u YOUR_USER HOST_ADDRESS

For example, to connect to host 192.168.1.50 with user test, you only type the following:

lftp -u test 192.168.1.50

McSonk

Posted 2013-07-23T16:29:23.483

Reputation: 101

1Worked great for me. Upvoted this and downvoted everything ahead of it. – ArtOfWarfare – 2018-07-23T17:10:19.873

9

If by weird you mean a long command line with both types of quotes, just avoid it. Use a script and save a bookmark. There are probably no better ftp clients than lftp.

  1. save your lftp script in a file
  2. run lftp without any arguments
  3. source the script
  4. save a bookmark.
  5. delete rhe script (to get rid of the clear-text password)

Use the bookmark in the future. You'll have to figure out if ssl options are saved for the bookmark or if you have to persist those settings via a global lftp configuration file.


Sample script.

$ cat lftp.ssl.commands
user moo foopass
set ftps:initial-prot "";
set ftp:ssl-force true;
set ftp:ssl-protect-data true;
open ftps://HOSTNAME:990

Sample output.

$ lftp
lftp :~> source  lftp.ssl.commands
lftp HOSTNAME:~> dir
`ls' at 0 [Connecting...]

Ярослав Рахматуллин

Posted 2013-07-23T16:29:23.483

Reputation: 9 076

6

Or you can do this in a bash script:

#!/bin/bash
lftp <<SCRIPT
set ftps:initial-prot ""
set ftp:ssl-force true
set ftp:ssl-protect-data true
open ftps://<hostname>:990
user <user> <password>
lcd /tmp
cd <ftp_folder_hierarchy>
put foo.txt
exit
SCRIPT

This shouldn't create any permanent lftp changes in /etc/lftp.conf, or ~/.lftprc, or ~/.lftp/rc

RyanS

Posted 2013-07-23T16:29:23.483

Reputation: 81

3

it will fail on some servers, because ssl settings should be passed before the open command not within it. example of working one:

lftp -c 'set ftp:ssl-allow true ; set ssl:verify-certificate no; open -u USERNAME,PASSWORD -e "cd /; mput LOCAL/PATH/TO/FILE/FILENAME.EXT; quit" HOST'

Abu-Sadek

Posted 2013-07-23T16:29:23.483

Reputation: 31

2

I try connect to proftpd server with above config but it cannot login so when I try this, it 's Ok.
1. Create a script config file

vi .lftprc

with below content:

set ftp:ssl-auth TLS
set ftp:ssl-force true
set ftp:ssl-protect-list yes
set ftp:ssl-protect-data yes
set ftp:ssl-protect-fxp yes
set ssl:verify-certificate no

  1. After that, connect to server:

    lftp username@hostname

and that's all OK for me now!

quan.nd

Posted 2013-07-23T16:29:23.483

Reputation: 21