LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-06-2008, 12:54 PM   #1
200mg
Member
 
Registered: Jul 2006
Posts: 88

Rep: Reputation: 15
FTP / Command line ftp quesion


Anyone know a way to do a command line ftp that logs into a server downloads what is in it, then deletes everything out of the source? I want to put this in a shell script to run in cron.

TIA
 
Old 05-06-2008, 01:59 PM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
If you have lftp installed, check the man page.
 
Old 05-06-2008, 02:54 PM   #3
hbirdguy
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Rep: Reputation: 0
I have used this script to receive files. Please note that I have edited this script to remove non-necessary code. It has not been tested as is appears below. It makes 2 connections, the first one receives the files. After moving the files to the destination directory and creating a list of files to delete, a second call deletes the files. If you need to navigate to a sub-directory at the remote site, add the command before the 'mget *' in the receive and output it at the beginning of the $DEL_LIST file in the delete session. Only files transfered will be deleted at the remote site.


Hope it helps.



<--------------------------------------- Cut here ------------------------------>
#!/bin/sh
#
# FTP_IN = working directory for ftp transfer
# FTP_FINAL = final directory for files on local machine
#
# Also, requires an entry in a .netrc file to define the user id and
# password for remote.system.
#
#

FTP_IN=/tmp/ftp_in
FTP_FINAL=/tmp/collected_files

#
# Log on remote to get files
#
# commands can ve added before mget * to navigate to a directory.
#
echo
echo "Logging on to the Remote ftp site..."
cd $FTP_IN
ftp -i remote.system << FTP_EOF > /dev/null 2>&1







mget *







quit
FTP_EOF

echo
echo "Files Received:"
echo
l $FTP_IN

echo
cd $FTP_IN

ls > /tmp/temp$$ 2>/dev/null

if [ -s /tmp/temp$$ ]
then : ok
else rm /tmp/temp$$
echo
echo
echo No files found to process!!
echo
echo
exit 0
fi


DEL_LIST=/tmp/edi.del$$
>$DEL_LIST

# echo cd sub_dir >> $DEL_LIST

if [ -s /tmp/temp$$ ]
then for file in `ls`

do mv $file $FTP_FINAL/$file
echo del $file >> $DEL_LIST
done
fi

rm /tmp/temp$$

echo >> $DEL_LIST
echo >> $DEL_LIST
echo >> $DEL_LIST
echo quit >> $DEL_LIST

ftp remote.system < $DEL_LIST > /dev/null 2>&1

rm $DEL_LIST

exit 0

<---------------------------- Cut Here ------------------------------->
 
Old 05-06-2008, 03:15 PM   #4
200mg
Member
 
Registered: Jul 2006
Posts: 88

Original Poster
Rep: Reputation: 15
thanks for the replies, I'll give your script a shot birdguy. I have something similar.

ftp file

Code:
open ftp.mysite.com
user user pass
binary
lcd /home/unixbox/test
mget *.txt
mdelete *.txt
bye
$:~/test
then i invoke from a diff script with

Code:
ftp -vim < ftp file
I'm coming from windows on this and the cmd line ftp for windows doesn't have an option to remote del, I find the one supplied with linux to be better

Last edited by 200mg; 05-06-2008 at 03:16 PM.
 
Old 05-06-2008, 03:21 PM   #5
hbirdguy
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Rep: Reputation: 0
If a file is added to the remote site between your mget and mdelete, it will be deleted without being received. I doubt this would ever be a problem, but it is a possibility.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
FTP Command Line (Scripting Multiple FTP gets) Critcho Linux - Software 3 01-04-2007 11:57 PM
FTP command line tommytomato Linux - General 5 01-13-2006 08:57 AM
what is different with Ftp From browser and Ftp from command line zahra79 Linux - Networking 2 06-22-2005 03:26 AM
Command Line FTP erikcw Fedora 3 10-12-2004 09:44 AM
ftp command line acrors Fedora 3 10-02-2004 04:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:04 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration