The Computer Oracle

How to download files from FTP site in one command line without user interaction (Windows)

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 3 Looping

--

Chapters
00:00 How To Download Files From Ftp Site In One Command Line Without User Interaction (Windows)
00:31 Answer 1 Score 21
00:56 Accepted Answer Score 9
01:07 Answer 3 Score 3
02:21 Answer 4 Score 3
03:36 Answer 5 Score 2
03:46 Thank you

--

Full question
https://superuser.com/questions/532130/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#windows #ftp #download

#avk47



ANSWER 1

Score 21


Try this: Batch files - Unattended FTP downloads

WGET ftp://ftp.mydomain.com/path/file.ext  

for anonymous downloads

or:

WGET ftp://user:password@ftp.mydomain.com/path/file.ext  

when authentication is required.


As @XavierStuvw pointed out via edits and comments, swapping WGET to a lowercase wget would work in linux.

wget ftp://user:password@ftp.mydomain.com/path/file.ext



ACCEPTED ANSWER

Score 9


I found the way:

echo open 192.168.0.1 >> ftp &echo user admin w00t >> ftp &echo binary >> ftp &echo get file.zip >> ftp &echo bye >> ftp &ftp -n -v -s:ftp &del ftp



ANSWER 3

Score 3


Note that you can ask for the syntax of a command in DOS by using the /? switch. For example:

C:\>ftp /?

Transfers files to and from a computer running an FTP server service
(sometimes called a daemon). Ftp can be used interactively.

FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-A] [-x:sendbuffer] [-r:recvbuf
fer] [-b:asyncbuffers] [-w:windowsize] [host]

  -v              Suppresses display of remote server responses.
  -n              Suppresses auto-login upon initial connection.
  -i              Turns off interactive prompting during multiple file
                  transfers.
  -d              Enables debugging.
  -g              Disables filename globbing (see GLOB command).
  -s:filename     Specifies a text file containing FTP commands; the
                  commands will automatically run after FTP starts.
  -a              Use any local interface when binding data connection.
  -A              login as anonymous.
  -x:send sockbuf Overrides the default SO_SNDBUF size of 8192.
  -r:recv sockbuf Overrides the default SO_RCVBUF size of 8192.
  -b:async count  Overrides the default async count of 3
  -w:windowsize   Overrides the default transfer buffer size of 65535.
  host            Specifies the host name or IP address of the remote
                  host to connect to.

Notes:
  - mget and mput commands take y/n/q for yes/no/quit.
  - Use Control-C to abort commands.

In your case, you'll want to use the -s switch to feed it a script, including the login responses.

For example:

  1. Create a script file (c:\scriptfile.txt) with the following contents:

    open
    servername_or_ip
    username
    password
    get
    /fullpath/thefile.txt
    c:\fullpath\thefile.txt
    quit
    
  2. execute ftp with the -s switch and specify the script filename

    C:\>ftp -s:c:\scriptfile.txt
    



ANSWER 4

Score 3


Here is another solution of how to download all files from a remote server folder to your local folder, using the command line and winscp scripting:

  1. Download and install WinSCP: https://winscp.net/eng/download.php

  2. Create a batch file e.g. "ftp-automate.bat" in a custom folder of your choice (e.g. "C:\customfolder").

  3. Edit the batch file "ftp-automate.bat" and add this content:

@echo off
echo Starting WinSCP
"C:\Program Files (x86)\WinSCP\WinSCP.com" /script="C:\customfolder\winscp-script.txt"
echo WinSCP finished
  1. Create the file "winscp-script.txt" in "C:\customfolder\winscp-script.txt" and add this content:
# Connect to SFTP server
open sftp://USERNAME:PASSWORD@HOSTORIP
# Download remote to local folder
get /var/lib/myfolderofinterest/* C:\mylocalfolder\
# optional: Remove remote files (remove #)
# rm /var/lib/myfolderofinterest/*
# Exit WINSCP
exit

Of course, you have to replace USERNAME with your FTP username, PASSWORD with your FTP password and HOSTORIP with your domain (ftp.mydomain.com) or IP address (12.34.56.78).


Security Note: Make sure the above script file on your PC is safe because it contains the credentials (password) to your server!


Tip: You might want to use Windows Task Scheduler (Action > Create Basic Task) to run the batch file once a day.