Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have to download files which are outside the my site directory using wget with windows let me make it more clear.

I have my site running on Linux server.

Domain  ---> www.example.com

/var/www/html ---> This is the my site directory

/home/username/data.csv  ---> This is the file I wants to download

When I try to download any file from the site directory it is working fine but it is not getting downloaded from here /home/username/data.csv

c:\wget\ wget.exe --ftp-user="username" --ftp-password="password" "www.example.com/index.php"

The above command works good and 'index.php' file is downloaded successfully.

But how to target /home/username/data.csv file and download using wget?

I tried with this but I was sure this will not work.

c:\wget\ wget.exe --ftp-user="username" --ftp-password="password" "www.example.com/home/username/data.csv"

I can understand why this command does not work and return 404 error, because the domain is pointing to the /var/www/html directory hence wget internally reads it like /var/www/html/home/username/data.csv and this is true there is no such file.

So my question is Does wget accept the path?

How do I do download the file outside my site directory?

share|improve this question
    
just looking at the jist, how about -H, to span hosts –  barlop Oct 5 '11 at 19:20
    
oh i see what you're asking, no you cannot obviously. It's simply not on the web or ftp server. though you could start another one on that directory. but ssh will let you copy any file from the terminal. –  barlop Oct 5 '11 at 19:22

2 Answers 2

up vote 0 down vote accepted

How do I do download the file outside my site directory?

You can't ask the web server to provide it, for security reasons.

Try using ftp instead

wget ftp://username:password@www.example.com/data.csv

If FTP service isn't available, configure it or use sftp instead, for greater security.

share|improve this answer
    
FTP service is not configured and I tried with SFTP wget sftp://username:password@www.example.com/data.csv but it says Unsupported Scheme –  Shakti singh Oct 5 '11 at 10:08
    
wget doesn't support sftp, there is a separate client program. For Windows you can use WinSCP or Putty's sftp. However you should first check that there is an sshd and sftpd service running on the server and you may need to set up some authentication credentials depending on how the server is configured. How do you upload files to the web-server? –  RedGrittyBrick Oct 5 '11 at 10:14
    
I did it with WinSCP. Thanks –  Shakti singh Oct 7 '11 at 9:21

Your web server is only serving files from the /var/www/html/ path and it doesn't know about the existence of /home/username/. You need to launch some kind of a web server instance inside /home/username/ before you can wget files from that directory.

Here are a couple of ways to make that work.


  • Start a temporary HTTP server instance using Python in your home directory.

$ cd /home/username

$ python -m SimpleHTTPServer (python -m http.server on Python 3.x)

$ wget http://example.com:8000/data.csv


  • Create a symlink to /home/username/ from /var/www/html/, though this is not recommended as it exposes your entire home directory. Or create the symlink to data.csv itself.

$ cd /var/www/html/

$ ln -s /home/username/data.csv data.csv (ln -s /home/username homedir to symlink the directory)

$ wget http://www.example.com/data.csv

Make sure, that you have enabled using symlinks (globally or for this Directory only) Options FollowSymLinks See here for more documentation regarding symbolic links.


share|improve this answer
    
okay will give a try –  Shakti singh Oct 5 '11 at 10:50
    
Thanks, I did not tried this way but i think this should work. I did this with WinScp. –  Shakti singh Oct 7 '11 at 9:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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