LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 04-06-2010, 09:57 AM   #1
dina3e
Member
 
Registered: Mar 2008
Location: Bangalore
Distribution: Enterprise Red Hat linux
Posts: 98

Rep: Reputation: 16
delete selected files from sftp


Hi,
i am trying to delete multiple files from sftp with non-interactive way as per the desire ext. But i am not able to get the proper extension of the files for removing files.

lftp -u ${user},${passwd} sftp://${ip}<<EOF
cd ${path}
rm *${ext}
bye
EOF
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-06-2010, 10:52 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
Might help if you gave an example of one or so of the files you are trying to remove.
 
Old 04-06-2010, 11:05 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
lftp does not perform globbing, unless you use the glob command so that the relevant line should read:
Code:
glob rm *${ext}
or eventually the mrm command which an alias for "glob rm":
Code:
mrm *${ext}
Let me note that maybe you don't really need to use lftp if your only task is to remove files. Most likely you have ssh access together with ftp and the code above could be reduced to one single line:
Code:
ssh $user@$ip "rm $path/*$ext"
Also note that it's not a good idea to store a password in clear text inside a script. If you can (or have) set-up Public Key Authentication for password-less connections, you can still use lftp and leave the password blank, e.g.
Code:
lftp -u ${user}, sftp://${ip} << EOF
The same applies to the ssh command above, without modifications.

Last edited by colucix; 04-06-2010 at 11:14 AM.
 
2 members found this post helpful.
Old 04-07-2010, 02:26 AM   #4
dina3e
Member
 
Registered: Mar 2008
Location: Bangalore
Distribution: Enterprise Red Hat linux
Posts: 98

Original Poster
Rep: Reputation: 16
@colucix
Thanks a lot for giving me such a valuable knowledge.
But here i got a strange output .

lftp -u ${user},${passwd} sftp://${ip}<<EOF
ls
cd ${path}
ls
bye
EOF

Here ls output is full listing of files, rather only name of files. also i am not able to change the desire path as in path variables.
 
Old 04-07-2010, 03:43 AM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
The long listing depends on the server settings, I'm afraid you cannot change this behavior from the client side. Regarding the path be sure to choose a path relative to the home of the sftp user. If you use a full path take in mind that on many servers users are chroot-ed. This means they see their home as /. You can easily verify that. If the path is correct, could it be a permissions problem?
 
  


Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Selected Rows in Perl/CGI ashok.g Programming 5 04-06-2010 11:30 AM
How to delete selected files? thomas2004ch Linux - Newbie 8 02-10-2010 12:50 PM
need to rsync only selected files (--files-from) also need to delete files on dest. ? BrianK Linux - General 5 10-22-2009 10:52 PM
sftp user cannot delete Velocity123 Linux - General 1 10-20-2007 02:43 AM
Files truncated by sftp/sftp-server at 65kb gato Linux - Networking 1 12-18-2003 11:29 AM


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

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration