What's the command for logging in with FTP all with one line?
ftp username:password@my.domain.com
says:
Password required for username:password
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityWhat's the command for logging in with FTP all with one line?
ftp username:password@my.domain.com
says:
Password required for username:password
ftp -nv yourftpserver.com
then user your_username
or user anonymous
I posted this answer since ftp ftp://username:password@my.domain.com
did not work for me.
Usage: { ftp | pftp } [-46pinegvtd] [hostname]
-4: use IPv4 addresses only
-6: use IPv6, nothing else
-p: enable passive mode (default for pftp)
-i: turn off prompting during mget
-n: inhibit auto-login
-e: disable readline support, if present
-g: disable filename globbing
-v: verbose mode
-t: enable packet tracing [nonfunctional]
-d: enable debugging
The best option is to use a .netrc along with something like gpg for security purposes.
I've written a general purpose script for this, which I may upload later, but it boils down to:
gpg -c .netrc
or optionally with a passphrase on the commandline and an output destination:
gpg --passphrase <secretphrase> -o .netrc.gpg -c .netrc
Not shown here, but you could additionally use asymmetric keys (if you have them setup) with gpg to make this even more secure.
Then when you are ready to login
gpg .netrc.gpg
# or
gpg --passphrase <secretphrase> -o .netrc .netrc.gpg
ftp yourservername
rm .netrc
An example .netrc:
machine google.com
login <username>
password <secretpassword>
I actually keep a local hash and the original copy of these files on a different computer than the one I that I use the .netrc files on, and verify the hash of the .netrc and the script that I run, but that is above and beyond the OP's original question.
chmod 600 .netrc
(3) a shell function as wrapper around the decrypt, ftp call, and removal of decrypted .netrc would be helpful. Thank you for your great answer!
– math
May 29 '19 at 6:57
You can try
my_ftp() {
ftp -i -n <<EOF
open $HOST
user "$USER" "$PASS"
$@
EOF
}
which you then can call with my_ftp $'ls subfolder\nanothercommand'
This solution is not interactive but the best I could figure out
edit: You are probably best off to just use curl instead.
Use netrc. It is better than giving the password away on the command line.
man ftp
to find out, or maybeftp --help
. Don't forget thatftp
may mean different utilities.... – Basile Starynkevitch Mar 3 '12 at 16:29ftp ftp://username:password@my.domain.com
– Zheileman Mar 3 '12 at 16:35