6

I am trying to ftp multiple files from one machine to another using a shell script. Below is my script:

ftp -nv <<EOF
open home.machine.com
user remote monday
binary
mput *.txt
bye
<<EOF

Now, the problem is, it hangs in between, but when I try each and every command on the command prompt. After I execute mput *.txt, it asks for confirmation for each and every file. When I enter yes then it moves on to the next file, and asks again.

Am I missing something?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
M.J.
  • 16,266
  • 28
  • 75
  • 97
  • 1
    Please remove '<<' chars in the beginning of last line cause it starts new block and commands after will be ommited by shell – Igor Jul 25 '13 at 09:52

4 Answers4

7

I tried something like this:

prompt
mput *.txt

The prompt command closed the user interaction, and then it worked properly.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
M.J.
  • 16,266
  • 28
  • 75
  • 97
3

From the manual:

-i Turns off interactive prompting during multiple file transfers.

Blagovest Buyukliev
  • 42,498
  • 14
  • 94
  • 130
  • i tried like `mput -i *.txt`, but that also didn't worked..am i using incorrectly.. when i tried this.. only 2-3 files gets ftp rest doesn't... – M.J. Jul 14 '11 at 18:07
2

Based on your code snippet, it should be like this:

ftp -inv <<EOF
open home.machine.com
user remote monday
binary
mput *.txt
bye
<<EOF

Notice the inclusion of '-i' in the ftp arguments.

Also, it is not advisable to use mput since it will be difficult to track errors compared to transferring files individually.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0
ftp -n ftp.test.com <<+
user ftpUser  password 
cd  local_dir/
lcd  remote_dir/
mget *.*
mdelete *.*
quit
bye
+
sun2
  • 1,118
  • 1
  • 13
  • 17