1

I'm trying to mirror a directory via FTP with wget. The command I'm using is

wget -m ftp://user:pass@192.168.1.1/foo/bar/

But, when I run it, I get the following:

--2018-10-10 15:01:32--  ftp://user:*password*@192.168.1.1/foo/bar/
       => ‘192.168.3.150/foo/bar/.listing’
Connecting to 192.168.1.1:21... connected.
Logging in as user ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /usr/user/foo/bar ... 
No such directory ‘foo/bar’.

I've searched the man pages, and googled, and I can't figure it out. How do I make wget actually download the directory "/foo/bar/", and not "/usr/user/foo/bar/"?

HiddenWindshield
  • 607
  • 5
  • 12

2 Answers2

4

A similar question on stackoverflow (which involved java instead of wget, but really the underlying problem is with the URL syntax which is hopefully language-independent) was resolved by adding another slash and URL-encoding it, like this:

wget -m ftp://user:pass@192.168.1.1/%2Ffoo/bar/

It works for me even without encoding, just with an extra slash:

wget -m ftp://user:pass@192.168.1.1//foo/bar/

The first slash is thrown away (serving only as a separator between host and path), and the second slash actually counts as part of the path.

0

You should be able to download a specific directory using wget like this:

wget -m 'ftp://[user]@192.168.1.1/%2ffoo/bar' -O /foo/bar

I would avoid putting your password into the URL as it will then appear in your bash history. This command of course means that /foo/bar is located off of / and not anywhere else. If /foo/bar is located off of something like /var/www you will need to include the full path in the command.

I take it you are using a UNIX-like based off of the /usr/user so there may be differences in the function of the specific implementation of wget you are using.

Here is an alternative using curl:

curl -u [user] 'ftp://192.168.1.1/%2fpath/to/foo/bar' -o /path/to/foo/bar

Please read over these links:

FTP URLs
How to use wget
Using wget to recursively download FTP directories
Download using wget to a different directory than current directory
How to specify the location with wget?
Downloading file from FTP using cURL

Please comment if you have any questions or issues with this answer. I highly suggest you read through each link I have provided thoroughly before attempting the commands. I appreciate feedback to correct any misconceptions and to improve my posts. I can update my answer as needed.

Best of Luck!

kemotep
  • 5,280
  • 7
  • 21
  • 36