problem in making sftp script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem in making sftp script
# 1  
Old 02-20-2008
problem in making sftp script

Dear all

I am bit new to shell scripting . I am implemented autossh between two sun solaris machines , so that when I use sftp it will not ask for the password.

Now I need to make shell script in which I have to transfer files from one server to another server automatically through root user. I try to make shell script for automatic transfer of files through sftp.

#! /bin/sh
sftp server1
lcd /girish
cd /amit
mput *
bye

after executing this shell script I have been put to sftp> prompt. When I exit from sftp , it give me three error lcd,cd mput command not found. It does not transfer files.

Please correct my shell script. I would be greatful for that.
# 2  
Old 02-20-2008
Quote:
Originally Posted by girish.batra
Dear all

I am bit new to shell scripting . I am implemented autossh between two sun solaris machines , so that when I use sftp it will not ask for the password.

Now I need to make shell script in which I have to transfer files from one server to another server automatically through root user. I try to make shell script for automatic transfer of files through sftp.

#! /bin/sh
sftp server1
lcd /girish
cd /amit
mput *
bye

after executing this shell script I have been put to sftp> prompt. When I exit from sftp , it give me three error lcd,cd mput command not found. It does not transfer files.

Please correct my shell script. I would be greatful for that.
Hi,
Create a batchfile with all the commands you wish to run then
Code:
server2:/tmp>cat batchfile
lcd /tmp/src
cd /tmp/dst
mput *
bye
server2:/tmp>sftp -b batchfile server1
sftp> lcd /tmp/src
sftp> cd /tmp/dst
sftp> mput *
Uploading file1 to /tmp/dst/file1
Uploading file2 to /tmp/dst/file2
...
sftp> bye

a simple scp could have done the trick, its all up to ya Smilie
# 3  
Old 02-20-2008
Thank for your reply brother

I know that simple scp can do the trick also. But my requirement is to do through sftp.

Problem is not as simple as you think. Actually I have to make a script in which I have to transfer 24 files of approximately 4 to 5 mb each (text based). My shell script should check the number of bytes of each files at server one then after transfer of all these files to server two it should check that all files have been transfer and also have the same number of bytes as in server one.

kind regards
# 4  
Old 02-20-2008
could anyone help me in this regard
# 5  
Old 02-20-2008
Try the following code and let me know if it works for you
Quote:
echo "cd <dirname> \n put <file> \n quit" |sftp -v <remoteUserid>@<Server> 1>sftp1.log 2>sftp2.log
grep -i transfer sftp2.log
# 6  
Old 02-21-2008
Dear Brother

First of all I would like to thanks for your reply. I have to modify your code a bit. Here is the code

At server1

# cat>abc
lcd /girish
cd /amit
mput *
bye

# cat>xyz
Sftp -B 131072 -b abc -v server2 1>sftp1.log 2>sftp2.log
grep -i uploading sftp1.log> output

When I execute the xyz file it gives me the files which are transfer & log into output file. -B used for fast transfer of files. If I don't give the -v option even then it work. But when I use -v option, kindly tell me where and in which file sftp do the loging.

One more thing is that output file only show the output when all the files are transfer. But suppose when I dissconnected the network during the transfe of files then it will not show any output. I need a solution in which if something happen during transfer of files then either sftp start sending all the files again or from where it was left.
# 7  
Old 02-21-2008
Girish,

Even without "-v" option the sftp works. But "-v" option gives the details of sftp connection and what exactly it is doing.
When you changed the code, you have grep'ed the 1st file (sftp1.log) instead of 2nd file (sftp2.log).

sftp1.log gives you the details of the command that is executed from the batch file but sftp2.log gives you the details of the connection such as servername, port, authentication of key, bytes per second and transfer status.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - sftp simple script problem

Hello, when running the scripts below I am not getting message bb2. Can you please help? #!/bin/bash TLOG=/tmp/bb/amatest.log FTPRESULTS=/tmp/bb/amlist export TLOG FTPRESULTS >$TLOG >$FTPRESULTS echo bb1 sftp -oPort=2222 XXXXXXXXXXXXX@sftp.userssedi.com <<EOF cd... (5 Replies)
Discussion started by: biljana
5 Replies

2. Shell Programming and Scripting

Problem in making a list with awk

Hi bodies,I am doing a list from a .txt file with awk commands but something is wrong. The .txt file looks like: 32782 28 18 32783 02 18 32784 01 18 32785 29 18 32786 25 23 32787 25 18 32788 00 18 32789 25 26 32790 02 23 32791 29 26 ... (2 Replies)
Discussion started by: Behrouzx77
2 Replies

3. Shell Programming and Scripting

sftp script - problem removing files remotely

Hello all, After searching through the similar topics and not finding a working solution, I decided to join and post my question (and maybe kill time and help other users). Essentially I am trying to get a file from the sftp and then delete it after the file is pulled. all the sftp commands... (3 Replies)
Discussion started by: MarcMaiden
3 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. UNIX for Dummies Questions & Answers

Problem automating sFTP transfer using script in cron

Hi Newbie here I am having problems with automating sFTP transfers. Just to save time - SCP is not an option as sFTP is stipulated by controllers of far end server. Ineed to automate sFTP transfer of a single file, once a day to a remote server to which i have no control over. I am using:... (6 Replies)
Discussion started by: robbien
6 Replies

6. Shell Programming and Scripting

Problem with SFTP script

Hi All, I can log in properly with my sftp handshake with the script, but can not get it to execute the lines of code for get commands within the script. Is there anything special with SFTP we need to do to make this work. I have went and looked on the message board but did not find anything... (3 Replies)
Discussion started by: wsiefkas
3 Replies

7. Shell Programming and Scripting

problem in making Awk executable script

Guys I placed #!path/awk -f placed awk script and used $1 to call 1st inputfile inside the script. But some where I did mistake. Could you please help me run this script as executable I forgot to mention I also used BEGIN before placing awk script. But nothing worked out. Script ... (2 Replies)
Discussion started by: repinementer
2 Replies

8. Shell Programming and Scripting

Problem in making itration

Hi, I have a file which keeps on appending the data continuously, i that i am looking for a particular pattern, if i dont find that pattern i want to wait for 30 seconds to check it again. can we use it like this ----------------------------- until do cat $line |... (1 Reply)
Discussion started by: Prateek007
1 Replies

9. Shell Programming and Scripting

Problem in making shell script

Dear all Dear Brother I am bit new to programming or shell scripting. I have given one shell script which is regarding combining all the 240 or less files in a particular folderwhich is related to one hour of the day. There will be 24 these kind of folders related to a day . It means there... (4 Replies)
Discussion started by: girish.batra
4 Replies

10. Programming

DDD making problem

Hi Everybody, I am trying to make the ddd-3.3.9 debugger. I installed all dependencies. this is what i get: # make Making all in themes make: Entering directory `/space/atoulan/ddd-3.3.9/themes' make: Nothing to be done for `all'. make: Leaving directory... (0 Replies)
Discussion started by: azazel11998
0 Replies
Login or Register to Ask a Question