LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-18-2006, 07:47 AM   #1
mewt
LQ Newbie
 
Registered: Mar 2005
Distribution: Fedora Core 4
Posts: 28

Rep: Reputation: 15
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 ?
 
Old 06-18-2006, 08:22 AM   #2
Theorist
Member
 
Registered: Jun 2006
Distribution: FC5, FC3, RHEL 3, Debian 3.1, Debian 3.0
Posts: 56

Rep: Reputation: 15
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

Last edited by Theorist; 06-18-2006 at 08:24 AM.
 
Old 06-18-2006, 02:22 PM   #3
mewt
LQ Newbie
 
Registered: Mar 2005
Distribution: Fedora Core 4
Posts: 28

Original Poster
Rep: Reputation: 15
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 ?
 
Old 06-18-2006, 02:35 PM   #4
mewt
LQ Newbie
 
Registered: Mar 2005
Distribution: Fedora Core 4
Posts: 28

Original Poster
Rep: Reputation: 15
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
 
Old 06-18-2006, 02:47 PM   #5
mewt
LQ Newbie
 
Registered: Mar 2005
Distribution: Fedora Core 4
Posts: 28

Original Poster
Rep: Reputation: 15
I also tried using mirror -R to mirror the whole directory to ftp but still says unknown command -c :S
 
Old 06-18-2006, 02:52 PM   #6
Theorist
Member
 
Registered: Jun 2006
Distribution: FC5, FC3, RHEL 3, Debian 3.1, Debian 3.0
Posts: 56

Rep: Reputation: 15
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

Last edited by Theorist; 06-18-2006 at 02:55 PM.
 
Old 06-18-2006, 02:59 PM   #7
mewt
LQ Newbie
 
Registered: Mar 2005
Distribution: Fedora Core 4
Posts: 28

Original Poster
Rep: Reputation: 15
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
 
Old 06-18-2006, 03:11 PM   #8
Theorist
Member
 
Registered: Jun 2006
Distribution: FC5, FC3, RHEL 3, Debian 3.1, Debian 3.0
Posts: 56

Rep: Reputation: 15
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
 
Old 06-19-2006, 08:47 AM   #9
Theorist
Member
 
Registered: Jun 2006
Distribution: FC5, FC3, RHEL 3, Debian 3.1, Debian 3.0
Posts: 56

Rep: Reputation: 15
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

Last edited by Theorist; 06-19-2006 at 08:50 AM.
 
Old 06-19-2006, 08:51 AM   #10
mewt
LQ Newbie
 
Registered: Mar 2005
Distribution: Fedora Core 4
Posts: 28

Original Poster
Rep: Reputation: 15
i tried the -e function too and still didnt work cos i didnt have the ""...thanks for your help
 
Old 06-19-2006, 09:17 AM   #11
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 52
An alternative method using normal ftp:
Code:
ftp -n host << EOF
user foo s3cr3t
cd /upload/
bin
mput bar.tgz
bye
EOF
 
Old 06-19-2006, 09:35 AM   #12
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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.
 
Old 06-19-2006, 09:50 AM   #13
Theorist
Member
 
Registered: Jun 2006
Distribution: FC5, FC3, RHEL 3, Debian 3.1, Debian 3.0
Posts: 56

Rep: Reputation: 15
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

Last edited by Theorist; 06-19-2006 at 09:52 AM.
 
Old 06-20-2006, 02:42 AM   #14
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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.
 
  


Reply

Tags
ftp, lftp, script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FTP with those functions needed :( utw-mephisto Debian 6 12-22-2005 08:57 AM
FTP Setup Help Needed. pdsst2 Linux - Networking 11 09-22-2005 08:18 AM
Good FTP program needed. eBopBob Linux - Software 7 08-15-2004 04:23 AM
ftp localhost -help needed dolvmin Linux - Networking 3 02-11-2004 12:18 PM
ftp help needed sulin Linux - Newbie 2 06-26-2001 09:48 PM


All times are GMT -5. The time now is 05:31 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration