Need Help on SFTP login from another server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help on SFTP login from another server
# 1  
Old 10-24-2012
Need Help on SFTP login from another server

Hi Experts,

I am writing one shell script. Below is the requirement

1. need to login to the SFTP server, go to the particular folder
2. take the file count in that folder and assign it to variable
3. came out of the SFTP server and check the condition, if the file count is less than the required count exit the script other wise further processing
4. then we need to move the files from SFTP to another server.
5. Need to check the file count in another server if all the files are not copied print the error msg and exit the script.

please help me with the sudo code. I am trying the below code it is getting error.

Code:
sftp ${SftpPort} ${userid}@${host name} "cd ${SFTP_SRC_DIR} <<sftp_test_EOF
count_src=`ls -ltr *.csv} | wc -l`
sftp_test_EOF"

echo $count_src

if [ $count_src -lt 3 ]
then
        echo "All CSV files not present in sftp"
        exit 1

fi


Last edited by Franklin52; 10-25-2012 at 05:58 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 10-24-2012
You can follow below steps:

1. Create a SFTP batch file:-

Code:
 
cat > sftp.cntrl
cd <destination dir>
ls -l *.csv

2. Run the SFTP batch file and get the count:-

Code:
 
count_src=`sftp -b sftp.cntrl $user@$host | awk '!/sftp/ { print; } ' | wc -l`


Last edited by Yoda; 10-24-2012 at 09:46 PM..
This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Not able to login AIX server but able to login thru console.

Hi, i am able to login to AX server thru console but not able to login directly thru server. also the server is not ping-able with other server. filesystem is fine. and OS version is AIX 5.3. please let me know if you need any specific log. thx in advance. Scriptor (2 Replies)
Discussion started by: scriptor
2 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. Shell Programming and Scripting

Login getting locked on sftp

Hey All, I have a ascript which sftp files from Solaris to Windows. I am usgin expect and sending password though script. I have observed that sometimes script works fine (manually or in cron) but after some run, the user I am usgin to connect is getting locked on Domain level. I am... (6 Replies)
Discussion started by: Deei
6 Replies

4. Shell Programming and Scripting

SFTP script to automate login in to remote server

Greetings, guys. I'm not much of a programmer forgive me for being a noob, because of someone leaving, I was put in an IT spot where I have to figure out a few things. Being new to Linux and programming has been a challenge. My boss has asked me to create an automated script to connect to a 3rd... (7 Replies)
Discussion started by: giovannym
7 Replies

5. Red Hat

Chroot sftp users, remote sftp login shows wrong timestamp on files

Hello, I have a weird issue, I have RHEL 5.7 running with openssh5.2 where sftpgroup OS group is chroot. I see the difference difference in timestamp on files, when I login via ssh and SFTP, I see four hour difference, is something missing in my configuration. #pwd... (8 Replies)
Discussion started by: bobby320
8 Replies

6. AIX

User Account Login Login on your AIX server

I want to learn AIX. I would like to find someone who would be willing to give me a login to their AIX home lab server. My intent is to poke around and discover the similarities and differences of AIX compared to other *NIXs. I am a UNIX admin so I can think of what some immediate concerns may... (1 Reply)
Discussion started by: perl_in_my_shel
1 Replies

7. Shell Programming and Scripting

sftp auto login

Hi, I looked into lot of posts on this question but i could not figure out the solution. we are using the following ftp shell program to send the file to target server. #!/usr/bin/ksh ftp -n -i<<EOF 2>&1 open <target server ip> user <username> <pwd> lcd /sc/doc/prd/FCSTP put file1.txt... (3 Replies)
Discussion started by: srrao.ch
3 Replies

8. Cybersecurity

APACHE: Tie in Web Page login with server login

Hello, I have created a web page on a server using apache and added .htaccess and .htpasswd in the folder for authentification. I was wondering if there was anyway to tie-in the login for this page with the login used to logon to the server. i.e. the same login info. is used for both, when... (1 Reply)
Discussion started by: WhotheWhat
1 Replies

9. Web Development

APACHE: Tie in Web Page login with server login

Hello, I have created a web page on a server using apache and added .htaccess and .htpasswd in the folder for authentification. I was wondering if there was anyway to tie-in the login for this page with the login used to logon to the server. i.e. the same login info. is used for both,... (2 Replies)
Discussion started by: WhotheWhat
2 Replies

10. HP-UX

SFTP silent login

Hi, I am connecting via SFTP to a remote Server. My problem is on trying to LOGin, I am asked for a password. I need to make this process automatic such that I can login without being prompted for a password. I can achieve this if the remote server has a simple FTP server and not SFTP. How... (6 Replies)
Discussion started by: sgaucho
6 Replies
Login or Register to Ask a Question