LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   ftp help needed (http://www.linuxquestions.org/questions/linux-general-1/ftp-help-needed-455915/)

mewt 06-18-2006 07:47 AM

ftp help needed
 
Hi,

Currently i need to create a shell script on my gameserver that will have to upload the day's CSS log files to another server...however i have no idea how to do this using ftp, since ftp only takes as arguments the hostname and port of the server in the following fashion..

ftp host port

and then drops into interactive mode. how can i make it upload a file named server.log to another ftp server ?

Theorist 06-18-2006 08:22 AM

Hi mewt,
Assuming that you have lftp, the Sophisticated file transfer program, installed, you can write a script for automating the file transfer.

So, please do the following and get back if you find any difficulties : -

Quote:

$ man lftp
With Regards,
Theorist

mewt 06-18-2006 02:22 PM

I tried doing using lftp but i only ended up being more muddled than before...i am trying to use the following:

lftp -c mput *.log -u user password -p 21 hostname

but im getting unknown command --u

:S any ideas why ? or what error im doing in the syntax ?

mewt 06-18-2006 02:35 PM

ok something is working now:

i used lftp <hostname> -u username,password -c mput *.log and lftp logged into the server and dropped me into a command line.. however the transfer of the log files did not start...


Mewt

mewt 06-18-2006 02:47 PM

I also tried using mirror -R to mirror the whole directory to ftp but still says unknown command -c :S

Theorist 06-18-2006 02:52 PM

Hi mewt,
Alright. So, here is how to create a script to be used with lftp. Do everything step by step.

First, open lftp : -
Quote:

$ lftp
Second, open a url with your username and password : -
Quote:

lftp :~> open -u username,password URL
Note:- you can also do $ lftp URL -u username,password in one step.

Third, upload all the .log files : -
Quote:

lftp username@URL:~> mput *.log
After that you want to disconnect, right :-
Quote:

lftp username@URL:~> bye
Now to make the script type all the above commands from second step onwards into a file named, say, ftp_script.

To run the script just run the following : -
Quote:

$ lftp -f ftp_script
With Regards,
Theorist

mewt 06-18-2006 02:59 PM

Thanks a lot! you were really of great help...i still wonder however why the command -c wouldnt work..AFAIK i was doing everything according to the manual of lftp :S

thanks

Mewt

Theorist 06-18-2006 03:11 PM

Hi mewt,
You should not just read the man page alone, but also try various possibilities, based on what it says.

mput -c wildcard option works very well for me. Try doing it separately, I believe it will work for you too.

Anyways, I am glad that you gave it a try. Keep the spirit up! Explore and find ways of doing things yourself. That is the best way of learning.

With Regards,
Theorist

Theorist 06-19-2006 08:47 AM

Hi Mewt,
Now I understood why -c option did not work for you. Earlier, I was thinking that you were talking about using -c option with mput command.

I got it. Firstly, you tried to run
Quote:

$ lftp -c mput *.log
which did not work. Then you tried to write
Quote:

open URL -u username,password -c mput *.log
in the script file and tried to run this script.

You need to put the command following -c enclosed in double quotes. But the following command
Quote:

$ lftp URL -u username,password -c "mput *.log"
will not work anyway.

Instead of -c if you use -e in the above command, it will work. If you read the man page, you will know why is that so.

With Regards,
Theorist

mewt 06-19-2006 08:51 AM

i tried the -e function too and still didnt work cos i didnt have the ""...thanks for your help

nx5000 06-19-2006 09:17 AM

An alternative method using normal ftp:
Code:

ftp -n host << EOF
user foo s3cr3t
cd /upload/
bin
mput bar.tgz
bye
EOF


timmeke 06-19-2006 09:35 AM

Quote:

enclosed in double quotes
??

Even without knowing the lftp command at all, I can tell you that double quotes won't help. The problem is that the shell will expand *.log into the list of files (in your current directory) which happen to have the .log filename extension, before passing everything to lftp. So, lftp will get to see something like:
... -c a.log b.log c.log etc
instead of '*.log'.

To prevent the shell from interpreting "*.log", you need to put it in SINGLE quotes, not double quotes.

It is probably better to enclose the entire FTP command in single quotes.

Theorist 06-19-2006 09:50 AM

Hi timmeke,
Quote:

$ lftp URL -u username,password -e "mput *.log"
will work! I only said that using -c option instead of -e will not work. Try doing it for yourself.

With Regards,
Theorist

timmeke 06-20-2006 02:42 AM

It may work, but it actually does (in FTP):
mput file1.log file2.log file3.log ...

not

mput *.log

This is a subtle difference, since both FTP commands should -in theory- work equally well. You may get into trouble if you have really many .log files with your approach. The single quote approach should always work.


All times are GMT -5. The time now is 08:35 AM.