Tux

...making Linux just a little more fun!

Unix

Terry T [timburwa at gmail.com]


Mon, 8 Oct 2007 09:16:18 +0200

Hie I am new UNIX.I want to copy 30 files with different names using the following command.

ftp -i -s:filename > logfilename.log

The command works well.

My problem is to type the same command 30 times for each file name. How do I transfer all the 30 files at the same time?


Top    Back


Thomas Adam [thomas.adam22 at gmail.com]


Mon, 8 Oct 2007 08:41:25 +0100

On 08/10/2007, Terry T <timburwa at gmail.com> wrote:

> Hie
> I am new UNIX.I want to copy 30 files with different names using the
> following command.
>
> ftp -i -s:filename > logfilename.log
>
> The command works well.

This is what the mcopy FTP command is supposed to do.

> My problem is to type the same command 30 times for each file name.
> How do I transfer all the 30 files at the same time?

You're most likely wanting a glob, or some iterative counter (or both), but until you tell us how these thrity filenames are related, none of us can help you.

-- Thomas Adam


Top    Back


Paul Sephton [paul at inet.co.za]


Mon, 08 Oct 2007 09:47:33 +0200

On Mon, 2007-10-08 at 09:16 +0200, Terry T wrote:

> Hie 
> I am new UNIX.I want to copy 30 files with different names using the
> following command.
> 
> ftp -i -s:filename > logfilename.log
> The command works well.
> 
> My problem is to type the same command 30 times for each file name. 
> How do I transfer all the 30 files at the same time?

MASK=*; for i in `ls $MASK`; do ftp -i -s:$i > logfilename.log done

where MASK is your file selection...


Top    Back


Neil Youngman [ny at youngman.org.uk]


Mon, 8 Oct 2007 08:49:26 +0100

On or around Monday 08 October 2007 08:16, Terry T reorganised a bunch of electrons to form the message:

> Hie
> I am new UNIX.I want to copy 30 files with different names using the
> following command.
>
> ftp -i -s:filename > logfilename.log
>
> The command works well.
>
> My problem is to type the same command 30 times for each file name.
> How do I transfer all the 30 files at the same time?

That looks like a different ftp client to the one I have. My man page does not show a -s option. There are as always a number of possible solutions.

You can use an ftp client that allows you to specify multiple files on the command line, e.g. ncftpput

Alternatively you can use a loop. If you are using the BASH shell a loop to send all files with the .txt extension in the current directory would look like

for file in *.txt do ftp -i -s:$file done > logfilename.log 2>&1

If you want to see error messages on the screen, while still capturing them in the log, you can use tee, e.g.

for file in *.txt do ftp -i -s:$file done 2>&1 | tee logfilename.log

HTH

Neil Youngman


Top    Back


Ben Okopnik [ben at linuxgazette.net]


Mon, 8 Oct 2007 08:22:10 -0400

On Mon, Oct 08, 2007 at 09:47:33AM +0200, Paul Sephton wrote:

> On Mon, 2007-10-08 at 09:16 +0200, Terry T wrote:
> > Hie 
> > I am new UNIX.I want to copy 30 files with different names using the
> > following command.
> > 
> > ftp -i -s:filename > logfilename.log
> > The command works well.
> > 
> > My problem is to type the same command 30 times for each file name. 
> > How do I transfer all the 30 files at the same time?
> 
> MASK=*; for i in `ls $MASK`; do 

There's no advantage to this over plain old

for i in *; do
-- 
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *

Top    Back


Paul Sephton [paul at inet.co.za]


Mon, 08 Oct 2007 14:30:32 +0200

On Mon, 2007-10-08 at 08:22 -0400, Ben Okopnik wrote:

> There's no advantage to this over plain old
> 
> ``
> for i in *; do
> ''

True.


Top    Back


Ben Okopnik [ben at linuxgazette.net]


Mon, 8 Oct 2007 08:44:09 -0400

On Mon, Oct 08, 2007 at 09:16:18AM +0200, Terry T wrote:

>    Hie
>    I am new UNIX.I want to copy 30 files with different names using the
>    following command.
> 
>    ftp -i -s:filename > logfilename.log
> 
>    The command works well.
> 
>    My problem is to type the same command 30 times for each file name.
>    How do I transfer all the 30 files at the same time?

As Thomas has already mentioned, the standard ftp client doesn't support the 's:filename' syntax - I can't say that I've ever seen one that does, myself. However, even with that available, it still may not be a great idea to loop over the file list; first, you may not have the list locally (after all, the files are remote!); second, unless your files are really huge, the overhead of logging in and logging out every time (whether it's automatic or not) is going to be significant - not to mention time-consuming and requiring constant interaction.

You'd be much better off using the 'mget' command in the standard client (don't forget to turn off the prompt - otherwise you'll be asked to confirm each filename before downloading):

you at localhost:~$ cd /your/download/directory
you at localhost:~$ ftp your_remote_host
[log in with username and password]
ftp> prompt
Interactive mode off.
ftp> cd remote/directory/where/your/files/are
250 Directory successfully changed.
ftp> mget *
...
Another way to do it is by using a more modern, capable FTP client - e.g., 'ncftpget' or something similar. Personally, I prefer to use my favorite file manager, Midnight Commander; it allows me to have a local directory open in one pane while I have a directory on the remote host open in another. I then select the files I want by using the 'Insert' key to highlight them, and press 'F5' to copy; 'mc' takes care of remembering all the funky FTP commands.

-- 
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *

Top    Back