LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-08-2012, 05:53 AM   #1
hackerdilli
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Rep: Reputation: Disabled
Question Help Me !! for sftp automation


Hey Guys i am wrtiting the scrtip in expect.
#Reuirment, to delete unnesscary files from Sftp
My Script,
i am able to loging into the sftp using the script,

#!/usr/local/bin/expect -f
set timeout -1
set host "xxxxxx"
set port "xxxx"
set uname "username"
set pwd "pass"

spawn /usr/bin/sftp $uname@$host -P$port
send "$pwd\n"
expect "sftp>"
#send "cd path/path1/path2\r"
#expect "sftp>"
send "ls $Line \r"
expect "sftp>"
send "quit \r"

Beyond this i want to put below given point in this script, that is ,

Read the name of uncessary file name from input file then check wheather is is avaible over the Sftp,If yes aviable then delete the file.

Could somebody help on this?

Regards
Prashant
 
Old 08-08-2012, 06:06 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
i would use ssh and set up logging in with keys so you dont have to be bothered with passwords.

should be as simple as:
Code:
 ssh user@host.net rm /path/to/filename
 
Old 08-08-2012, 06:20 AM   #3
hackerdilli
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi ,

Buddy dnt have option of ssh and have around 300 files. i need to enter the input through text file and put into the loop to check wheather is present or not .. if yes then i want to delete..

Thanks for replying..

Quote:
Originally Posted by schneidz View Post
i would use ssh and set up logging in with keys so you dont have to be bothered with passwords.

should be as simple as:
Code:
 ssh user@host.net rm /path/to/filename

Last edited by hackerdilli; 08-08-2012 at 06:25 AM.
 
Old 08-08-2012, 06:26 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by hackerdilli View Post
Hi ,

Buddy dnt have option of ssh and have around 300 files.
seems kinda' odd to me that you dont have access to ssh but you have the ability to sftp eventhough they use the same port and protocol ?

the fact that you have so many files to operate on means you should be using an automated program like ssh rather than a program like sftp whose function it is to prompt the user for input and wait until that input is selected.

use ssh to operate on your loop-control-variable. i wouldnt put in a check to delete but i guess it is up to you. i usually just rm a list of stuff whether it was there or not meaning that its not a big deal if it doesnt exist because it wouldve been deleted anyways (its like turning off a light switch thats already off).

Last edited by schneidz; 08-08-2012 at 06:30 AM.
 
  


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
LXer: Restricting Users To SFTP Plus Setting Up Chrooted SSH/SFTP (Debian Squeeze) LXer Syndicated Linux News 0 09-06-2011 07:10 AM
How do I use sftp to upload my web site? (no sftp tar command) johnMG Linux - Networking 6 06-21-2005 09:14 PM
sftp automation for downloading files chipix Linux - Security 5 07-14-2004 05:57 AM
Files truncated by sftp/sftp-server at 65kb gato Linux - Networking 1 12-18-2003 10:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:32 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