SFTP script help is needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SFTP script help is needed
# 1  
Old 01-04-2010
Wrench SFTP script help is needed

Hello all and Happy 2010!
I have following problem and I do not have a full solution yet.
Maybe someone of you could help ....

I have remote sevrer A and I am connecting from my local server via SFTP to download .TXT files.

-Files are dropped at random times into download folder on server A
-I can download files using SFTP script

Goal:

I need to delete files from remote server (A), after transmission was succesful (validation part)
and i cant get this thing working

Only what i am allowed to use is SFTP .

please if you have suggestion ...shed some light on me
Thank you
# 2  
Old 01-04-2010
Have you tried searching for SFTP and script on this site? This sort of question has arisen numerous times before and so you should be able to find answers already.
# 3  
Old 01-05-2010
Yes, I have tried to find something that i could use to solve this problem, but was unable to find here or posted on other forums. Even the problem appear to be trivial, it is not due validation part.
thanks for reply
# 4  
Old 01-05-2010
After you have received the first batch, and sucessfully processed them, create a text file that looks like:
cd somewhere
delete file1.txt
delete file2.txt
...
mget *
quit

Then use this file as input to your next sftp session.
You will be deleting the files from the remote server just before retrieving the next batch.
# 5  
Old 01-05-2010
Have done similar to this (recalled from memory) for ftp, I have not tried it for sftp:
Code:
# get files from sftp server
mkdir temp.$$
cd temp.$$
sftp << HERETEXT1
cd directory
bin
prompt
mget *
exit
HERETEXT1

# now delete files you have downloaded from sftp server
for FILE in *; do
sftp << HERETEXT2
cd directory
del ${FILE}
exit
HERETEXT2
done

I haven't tested this so do test it!

This assumes you have set up passwordless SSH for the account that is doing the sftp.
# 6  
Old 01-05-2010
Something to consider.
The size of the files to be downloaded, and the frequency of collecting them.
Eventually you will download a file that is still in the process of being created.
You can overcome this, by creating two files for each download, the first the actual data file, and the second a one character file (same name different extension) to indicate the the file is complete.
Only process the received file if there is a corresponding second file.
# 7  
Old 01-05-2010
Thanks so much for input!
yes, i have setup pwdless ssh and certs and its working just fine.
Will try to test yours suggestions!

I appreciate your help.
Thank you!

---------- Post updated at 03:29 PM ---------- Previous update was at 03:27 PM ----------

Jgt,
"Something to consider.
The size of the files to be downloaded, and the frequency of collecting them.
Eventually you will download a file that is still in the process of being created.
You can overcome this, by creating two files for each download, the first the actual data file, and the second a one character file (same name different extension) to indicate the the file is complete.
Only process the received file if there is a corresponding second file."


Do you know how i could do that?
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP or scp with password in a batch script without using SSH keys and expect script

Dear All, I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Discussion started by: ss112233
5 Replies

2. Shell Programming and Scripting

Needed SFTP script from windows to UNIX server and from UNIX to windows server(reverse SFTP)

hi guys, i need a script to sftp the file from windows to unix server ....(before that i have to check whether the file exists in the windows server or not and again i have to reverse sftp the files from unix to windows server..... regards, Vasa Saikumar. (13 Replies)
Discussion started by: hemanthsaikumar
13 Replies

3. UNIX for Dummies Questions & Answers

Sftp education needed

I have a program running on unix that creates a text file as part of a triggered event. the text files are written to the same directory everytime. There are 15+ users that could possibly be creating the files. Once the file is created, I need to move the file to a third party system. the only... (2 Replies)
Discussion started by: jdboydinaz
2 Replies

4. Shell Programming and Scripting

SFTP-how to log individual sftp command error while executing shell script

Hi, I have situation where i need to automate transferring 10000+ files using sftp. while read line do if ; then echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt fi done< files.txt sftp -b sftpCommand.txt stu@192.168.2.1 The above... (1 Reply)
Discussion started by: noobrobot
1 Replies

5. Shell Programming and Scripting

Help needed to setup SFTP

Hi Gurus, We need to make SFTP in non_interactive mode. I have done steps like key generation, copying public key into destination server, changing file/folder permission. Still we are not able to achieve it. Please check the log below.... $ sftp -v b2cint@10.76.120.120 Connecting to... (1 Reply)
Discussion started by: Sabari Nath S
1 Replies

6. UNIX for Dummies Questions & Answers

Help needed for listing files using SFTP

Hello All I want to list files using SFTP. this should work the same way as ls -Ap1t $dir is working in a perl program. but for SFTP i dont find any option like as A,p,1,t.so how to use this (0 Replies)
Discussion started by: vikas_poonia
0 Replies

7. Shell Programming and Scripting

sftp script needed for solaris box

Hi , I have a solaris box through which i need to connect to ATM's and pull files using sftp. I did same type of scripting using ftp before but no sftp.The problem now i am facing is, i want to put the password along with this sftp (non-interactive) script. Unfortunately there is no... (3 Replies)
Discussion started by: Renjesh
3 Replies

8. Shell Programming and Scripting

Help needed with secure shell "sftp"

I am using sftp -V sftp: F-Secure SSH 3.1.0 (build 12) on sparc-sun-solaris2.8 I think it's happening due to secure shell. I can not rename files with "get". As "get" is working fine with open shell sftp. Here are the details about the problem: "get" does not rename the file. It actually... (0 Replies)
Discussion started by: val0822
0 Replies

9. UNIX for Dummies Questions & Answers

Sftp Help Needed!!!!!!!

Thank you for the help (2 Replies)
Discussion started by: scooter17
2 Replies

10. Shell Programming and Scripting

sftp script needed

Hello all, need help to write a smal script to send files to remote sys using sftp @ HP UNIX environment. Thanks (1 Reply)
Discussion started by: ravi.sadani19
1 Replies
Login or Register to Ask a Question