I've tried to connect to a server via wget:

wget http://<user>:<pass>@serveradress

But wget responds: invalid port

I know that the server accepts incoming traffic at port 80. How can I fix this issue?

  • I don't think you can reliably use the user:pass@name syntax there; wget has separate command line options for those instead, so is probably naively parsing the string after the : as a port number. – geekosaur Mar 5 '11 at 3:02
up vote 143 down vote accepted

Wget interprets <pass>@serveraddress as port. To specify a username and password, use the --user and --password switches:

wget --user user --password pass http://example.com/

From man wget:



Specify the username user and password password for both FTP and HTTP file retrieval. These parameters can be overridden using the --ftp-user and --ftp-password options for FTP connections and the --http-user and --http-password options for HTTP connections.

  • 28
    I prefer the --ask-password option described by Nabil Kadimi's answer. It has you enter the password invisibly on another line and avoids storing it in your shell history. – Kevin Apr 8 '14 at 1:23
  • 6
    @Kevin You can avoid storing it in the shell history by starting the line with at least one space (as shown by Nabil). If the password/resource is sensitive, then you should worry more about the unencrypted HTTP/FTP/whatever connection than storing it on your disk. – Lekensteyn Apr 8 '14 at 8:58
  • I agree to the unencrypted password issue being more important in some cases than the shell history, but the answer is also useful for secure protocols. Also, sometimes you DO have to worry more about spies that have access to your computer than online spies (that are not interested by the content you're accessing or for which you don't care). The --ask-password answer below is clearly better for interactive usage, while the --password answer here is easier for automation. The comment by Ixgr about .wgetrc and chmod is also interesting in some cases. – youen Jul 17 '17 at 12:21

You have 3 options and here there are in no specific order other than guts feeling:

1/ Password is visible to anyone (using the command history)

me@machine:~$ wget --user=remote_user --password=SECRET ftp://ftp.example.com/file.ext

The password will also be visible in ps, top, htop and similar.

2/ Password is visible to anyone looking behind your shoulders

me@machine:~$  wget --user=remote_user --password=SECRET ftp://ftp.example.com/file.ext

Notice the white space before the command, it prevents saving it to your history

The password will also be visible in ps, top, htop and similar.

3/ Password is not visible to anyone including you

me@machine:~$ wget --user=remote_user --ask-password ftp://ftp.example.com/file.ext
Password for user `remote_user': [SECRET (not visible)]
  • 5
    While it is not visible in history, it is visible to all who conduct a ps, top, htop or similar command while the process is running. – user412812 May 22 '15 at 20:04
  • 4
    @AbdennourTOUMI Why would you disable certificate checks, especially if you are sending a password with the request? That is definitely not advisable in general. As far as "hiding" the password on logs or /proc is concerned, the wget manpage gives an additional option: "To prevent the passwords from being seen, store them in .wgetrc or .netrc, and make sure to protect those files from other users with "chmod"." – lxgr Jun 10 '16 at 9:32
  • 1
    If --ask-password is not available or you don't want to type the password every time, wget -i link.txt can help, where link.txt contains ftp://remote_user:SECRET@ftp.example.com/file.ext – tehnicaorg Apr 27 at 13:57

The command could have used --http-user and --http-password instead of --user and --password. In case of ftp request the options are --ftp-user and --ftp-password.

  • 1
    This is not entirely correct: man wget indicates that --user and --password are valid options, which can be overridden by --http-user or --ftp-password – Charles Green Jun 15 '17 at 13:04

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.