How do I FTP multiple files from the command line?

25

3

I would like to FTP the contents of a directory, but I can't seem to find the right way to use a wildcard. It seems like this would be a common thing to do; is my whole approach wrong?

The command is

ftp -s:"C:\Scripts\ftp01" ftpserver.domain.com

The script that is called is below. Updated per billinkc.

username
password
ascii
cd "/destinationfolder"
lcd "C:\Backup"
mput *.bak
close
quit

The script starts, no files are copied and the FTP session remains open.

230 User username Logged in Successfully
ftp> ascii
200 TYPE Command OK A
ftp> cd "/destinationfolder"
250 Directory successfully changed to "/destinationfolder"
ftp> lcd "C:\Backup"
Local directory now C:\Backup.
ftp> mput *.bak
mput 9829980.bak? close
mput 6406766.bak? quit
ftp>
ftp>

Conclusion

I needed to add the flag to suppress the PROMPT command:

ftp -i -s:"C:\Scripts\ftp01" ftpserver.domain.com

mmcglynn

Posted 2011-11-16T14:47:23.107

Reputation: 599

Answers

36

Before issuing the mput command, issue a prompt command to disable Interactive Mode. Once that's off it shouldn't ask you to confirm each file for the mput (or an mget).

Ƭᴇcʜιᴇ007

Posted 2011-11-16T14:47:23.107

Reputation: 103 763

3For those wondering "what is the syntax of this prompt command", you literally just type "prompt" and it toggles prompting from true to false. – Noumenon – 2017-01-08T12:24:39.340

2

Another way of disabling interactive prompting is to use the -i flag on the ftp command itself (e.g. ftp -i -s:"C:\Scripts\ftp01" ftpserver.domain.com). The docs describe the -i option as: "Turns off interactive prompting during multiple file transfers."

– Jesse Webb – 2017-08-11T20:11:34.233

3

I've never tried using the pathname for local folders, but I have done it by changing the local directory (lcd):

username
password
ascii
cd "/destinationfolder"
lcd Backup
mput *.bak
close
quit

billinkc

Posted 2011-11-16T14:47:23.107

Reputation: 365

2

Try inserting the line prompt n just before the mput line

horatio

Posted 2011-11-16T14:47:23.107

Reputation: 3 345

1

Use the mput command to put multiple files.

Chris S

Posted 2011-11-16T14:47:23.107

Reputation: 5 907

1Yes, that's what I am using – mmcglynn – 2011-11-16T14:58:13.180

Behind a firewall (particularly SOHO or cheap business grade units)? The built in ftp in Windows doesn't support PASV mode, so the transfer will hang and never complete. – Chris S – 2011-11-16T15:11:26.960

1

If you have administrator rights, you can install ncftpput. It is easy to use and great for recursive FTP uploads. The switch for recursive transfer is -R.

The software is included in most Linux distributions. For Windows it is installable with Cygwin.

Tim Haegele

Posted 2011-11-16T14:47:23.107

Reputation: 247

1

As Tim Haegele mentioned, ncftp does this very smoothly on Linux, if you are able and willing to install it:

sudo apt-get install ncftp
ncftp -R ftpserver.domain.com . /Scripts/ftp01

Collin Anderson

Posted 2011-11-16T14:47:23.107

Reputation: 169

0

This is the script that I used and that worked for me.

For ftp1.bat (script):

ftp -i -s:\tmp\ftp.txt

For ftp.txt (script):

Open ip
username
password
prompt
lcd C:\YourFolder\YourFolder
binary
cd /DestinationFolder
prompt
mput *.bak
cd ..
disconnect
quit

Maybe there're parts that aren't necessary but I'm putting it as it worked for me, hope it helps

Adrian Chacon

Posted 2011-11-16T14:47:23.107

Reputation: 1