Hello Marco,
If you're committed to using the pase ssh and Expect then I'm not much
help but if you're looking for alternatives then our sftp client will
let you do this very easily (and it's free). It supports password
authentication if that's been your problem. It'll let you build dynamic
lists, check remote file modified dates etc and even do a "double check"
on file sizes before you choose to delete anything. You can get a copy here:
www.arpeggiosoftware.com
Tim
On 3/15/2013 2:35 PM, Marco Cecchi wrote:
Hello Brad,
sincerely I don't care if I don't get a "just created" file (so your step 3 is unnecessary in my case), while it's a problem if I delete it without havin' got it.
Working under SSH script without a pair key, I need to use EXPECT utility and I think it's a little bit different from a dos batch file.
However can you write me the code part where you can extract files name to pass to GET and RM commands?
Thanks & Regards,
Marco
-----Messaggio originale-----
Da: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] Per conto di Bradley Stone
Inviato: venerdì 15 marzo 2013 14:22
A: Midrange Systems Technical Discussion
Oggetto: Re: Loop on remote dir with except sftp script for get and rm each files
I wrote a script like this once in DOS batch and what I did was this..
1. Get a list of all the remote files to download. This was done by redirecting the results of the DIR command to a file.
2. Use that list to build the FTP script to retrieve files. This is instead of using a *.* for MGET. One GET per item in the list worked so I got everything that was there, and left anything new alone.
3. When done, I would make another list of local files, and compare it to the remote file list to check for any errors.
4. If all was good, I used the initial remote list to remove files from the serve. This way you'll never touch any new files on the server.
Worked slick. :)
Brad
www.bvstools.com
On Fri, Mar 15, 2013 at 6:03 AM, Marco Cecchi <MarcoCecchi@xxxxxxxxxxxx>wrote:
Hello,
I created a simple script that get all files in a remote then delete all:
______________________________________________________________________
_
#!/usr/local/bin/expect -f
set timeout 20
spawn sftp $env(SSH_USER)@$env(SSH_HOST) expect {
default {exit 2}
"continue connecting (yes/no)?" {send "yes\n"; exp_continue}
"assword:" {send "$env(SSH_PASS)\n"; exp_continue}
"sftp>"
}
send "get * /XML/OrdFor/Ricevuti/\n"
expect {
default {exit 2}
"not found" {exit 0}
"sftp>"
}
send "rm *\n"
expect {
default {exit 2}
"not found" {exit 3}
"sftp>"
}
send "quit\n"
exit 0
It "works" but files in that directory are dynamics so I risk to
delete someone just arrived after I copied the rest.
So I'm looking for a sample code to cycle the remote directory in
order to GET and RM each single file.
Thanks in advance,
Marco Cecchi
DATACOM Srl
______________________________________________________________________
___________________________________________
Ai sensi del D. Lgs. 196/03 si precisa che le informazioni contenute
in questa e-mail ed eventuali suoi allegati sono riservate e ad uso
esclusivo del destinatario. Qualora il messaggio Vi fosse pervenuto
per errore, Vi invitiamo ad eliminarlo senza copiarlo e a non
inoltrarlo a terzi, dandocene immediata comunicazione. Grazie.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take
a moment to review the archives at
http://archive.midrange.com/midrange-l.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.