Convert SSH portion to SFTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert SSH portion to SFTP
# 1  
Old 06-12-2013
Convert SSH portion to SFTP

I just discovered that my company cant use ssh because they have so wack way of retrieving files without using key-authication.

I need to convert a portion of my script form ssh to sftp.

Here I am logginginto the machine to print a list of files.
Code:
while read line; do
	host=$line
	ssh $user@$host ls -l $directory $src_file_name$param'*' > ftpList$i.txt

I need to convert that to sftp. How do I do that?
# 2  
Old 06-12-2013
Try using a batch mode script like this:

Code:
echo 'ls -l $directory $src_file_name$param*' > cmd_file
while read line; do
	host=$line
	sftp -b cmd_file $user@$host > ftpList$i.txt

# 3  
Old 06-12-2013
This is an example of a inline sftp in shell script:
Code:
#!/bin/ksh
# test_sftp.sh
sftp -b /dev/stdin -v -o BatchMode=yes -o IdentityFile=/export/home/user/.ssh/id_rsa -o Port=22 user@host <<ENDSFTP
cd /home/user/test
put /export/home/user/test/test.txt test.txt.xferring
rename test.txt.xferring test.txt
quit
ENDSFTP
rc=$?
if [[ $rc != 0 ]]    then
    print "Error occured...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
else
 print "Successful transfer...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
fi


Last edited by Scott; 06-12-2013 at 08:05 PM.. Reason: Removed FONT tag AGAIN
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

restricting sftp and ssh for a user

I want to know if there is any way to set up a users home directory access with a restricted shell and allow them to SFTP to the directory. I want to allow the user to SSH into their home directory but no where else on the AIX server. I also want the user to be able to SFTP files to their home... (1 Reply)
Discussion started by: daveisme
1 Replies

2. Shell Programming and Scripting

ssh/sftp connection refused

Hi all, I logged on to a Unix server and am trying to connect a remote Windows server (Windows NT) via SSH/SFTP. However I always got the following error, sftp username@host_server (or ssh username@host_server) ssh: connect to host host_server port 22: Connection refused Any advise... (1 Reply)
Discussion started by: isaacniu
1 Replies

3. Shell Programming and Scripting

sftp ssh-keygen

sftp username@host <<EOF lcd /home/dirA cd /home/dirB mput *.txt exit EOF Hi, i have done the keygen-ssh settings but rite now I log through putty I enter my credentials and then when i successfully log in, then I issue the command ssh server name then I again enter into the server but... (1 Reply)
Discussion started by: rahulsxn660
1 Replies

4. Solaris

SFTP from SSH2 to SSH

Hi, Earlier, I have configured SFTP successfully in my prev jobs. This time I have to configure SFTP for local server (uses SSH2) and remote server (uses SSH). I tried to search the forum. I did not find the right thread. I appreciate your help. The following is the additional info >... (5 Replies)
Discussion started by: bobbygsk
5 Replies

5. Solaris

Fsecure ssh client sftp 2.5

Is there any free version of Fsecure ssh client sftp we have. or need to buy license for this. Can you please let me know on this.thanks Regards. (6 Replies)
Discussion started by: vijill
6 Replies

6. Shell Programming and Scripting

Password less connection(sftp/ssh)

Dear All, I'm trying to configure a passwordless connection between two servers of HP-UX. i have srearched the configuration in google so many times and as per the guidence i have done all the steps, but still its not working and every time it is asking for password while trying to scp some file... (2 Replies)
Discussion started by: panknil
2 Replies

7. UNIX for Dummies Questions & Answers

Locked out of ssh and sftp

I've been having troubles where i get locked out of shh and sftp. It happens overnight and when i come in the next day i have been locked out and can't seem to log in to the server through ssh or sftp. It is a co location server and each day i am having to have the hosts restart my server. When... (2 Replies)
Discussion started by: timgolding
2 Replies

8. Shell Programming and Scripting

SSH and SFTP

remotePath=$1 fileName=$2 remoteUser=$3 remoteServer=$4 echo " if ; then echo '0'; else echo '1'; fi " > temp_command.log command1=`cat temp_command.log` ssh $remoteUser@$remoteServer $command1 rm temp_command.log Above code is to check whether the file in remote server is exist. It... (1 Reply)
Discussion started by: suigion
1 Replies

9. UNIX for Advanced & Expert Users

ssh/sftp failure connection

Hello, I just want to ask regarding the meaning of the error that we got using sftp: Connecting to <TARGET SERVER IP>... @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @... (3 Replies)
Discussion started by: james_falco
3 Replies

10. AIX

SFTP Issue with ssh

Hello all, hopefuly this is the right place to post this. I am having an issue with a new sftp process on an AIX box. I created id_rsa.pub file and sent it to the person who runs the sftp process. He added the key to the authorized_Users (I only have phone contact with him and its an outside... (7 Replies)
Discussion started by: dbridle
7 Replies
Login or Register to Ask a Question