Shell script, sftp logfile not showing transfer information


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script, sftp logfile not showing transfer information
# 1  
Old 08-12-2016
Shell script, sftp logfile not showing transfer information

Hello,
Recently I have changed some crontab scripts which I execute to do different tasks mainly transfering some files from one server to the other.
The main change was the protocol from ftp transfer to sftp. Ftp server was the MS Windows default service, and Sftp server is an proprietary sw (attachmate).

My question has to do with the output (log file) of the script which doesn't show transfer info (size and bandwidth)
Below the differences between the ftp scripts log and sftp

FTP log output:
Code:
Connected to SERVER.
220 Microsoft FTP Service
331 Password required
230 User logged in.
200 Type set to I.
250 CWD command successful.
Local directory now /dir
200 PORT command successful.
125 Data connection already open; Transfer starting.
226 Transfer complete.
1836 bytes sent in 0.001078 seconds (1663 Kbytes/s)
local: file1.txt remote: file1.txt
250 CWD command successful.
200 PORT command successful.
125 Data connection already open; Transfer starting.
226 Transfer complete.
1836 bytes sent in 0.000823 seconds (2179 Kbytes/s)
local: file1.txt remote: file1.txt
221 Goodbye.


SFTP log output:
Connected to SERVER.
sftp> cd DIR
sftp> lcd /dir
sftp> put file2.txt
Uploading file2.txt to /Home/DIR/file2.txt
sftp> bye

Is it possible to have the size of sftp transfer and bandiwdth like for ftp?

Regards,
Enid


Moderator's Comments:
Mod Comment Use code tags, thanks.

Last edited by zaxxon; 08-12-2016 at 11:20 AM..
# 2  
Old 08-12-2016
What be the effect of the sftp option
Quote:
-v Raise logging level. This option is also passed to ssh.
# 3  
Old 08-15-2016
Hi RudiC,
I tested with the passing of -v parameter to sftp but I do get a lot of debug information for ssh which is not really useful for me.
On the last lines I get some information about the transfer rate and file size but it it somehow different from the easy readable output of ftp

sftp -v :
Code:
....
a lot of debug info
.....
Transferred: sent 2960, received 2712 bytes, in 0.6 seconds
Bytes per second: sent 5001.1, received 4582.1

ftp:
Code:
1836 bytes sent in 0.001078 seconds (1663 Kbytes/s)

I also tested by enabling the progress meter of sftp but again on the final output log I do not get any transfer/size information.
Strange because when I execute manually the sftp commands from shell I do get the output info:

Code:
root/server:/>sftp user@$SERVER
Connected to SERVER
sftp> put dates.txt
Uploading dates.txt to /Home/dates.txt
dates.txt                                                                                100%   55     0.1KB/s   00:00    
sftp>

Meanwhile with the below script which I use I do not have this info on the logfile:
Code:
#!/bin/ksh
DATEF=`date +%Y%m%d`
DATED=`date +%d%m%y`
LOCALDIR='/root'
REMOTEDIR='Upload'
FTPLOG=PutFile_test-$DATED.log
SERVER=192.168.9.9
NEWFILE=dates.txt

(
cd $LOCALDIR
sftp user@$SERVER <<EOF
progress
lcd $LOCALDIR
put $NEWFILE
bye
EOF
) 2>&1 |tee $LOGDIR/$FTPLOG

Regards,
Enid
# 4  
Old 08-15-2016
The progress meter uses terminal control codes and thus is not (utmost) suitable for text/log files. So sftp suppresses it when it detects it is not logging to the screen. How about
Code:
sftp -v ... |& tail -2

?
# 5  
Old 08-22-2016
Hi,
I did the change you mentioned (like below) but the script hangs and I do not get any output

Code:
(
cd $LOCALDIR
sftp -v user@$SERVER <<EOF |& tail -2
progress
lcd $LOCALDIR
put $NEWFILE
bye
EOF
) 2>&1 |tee $LOGDIR/$FTPLOG

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Execute a script after SFTP transfer

Hi All, I am having an issue with the script execution. I am having a SFTP process that send files to a location . I want to execute a script once it transfer the file to that location. Right now I am leveraging autosys file watcher to do that. Is there any way like MFT PPA that can execute... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies

2. Shell Programming and Scripting

SFTP script using firewall information

Hi, i have a scripts which transfer a file from source to dest server. It uses the firewall information like IP, USERNAME, PASSWORD. I wanted to know it belongs to source system firewall or the destination firewall info. How to check that firewall connection is working or no without running... (1 Reply)
Discussion started by: Pranavi
1 Replies

3. UNIX for Dummies Questions & Answers

Shell script to email logfile

Hi, I am trying to write a shell script to send a log file of a query run in oracle.Pls help me I am very new to shell scripting. echo " Checking Activity Spec " sqlplus / as sysdba <<END_SQL @activity_spec_metadata.sql quit;>>logfile END_SQL mailx -s "Checking Activity Spec schedule... (1 Reply)
Discussion started by: Rossdba
1 Replies

4. Shell Programming and Scripting

How to tail -f multi logfile in 1 shell script.?

Hello, How to tail -f multi logfile from multi path in 1 shell script. File & Path /usr/home/localmode/mode110l/log/logic/number110/digit110_digit110m4_2013050210.txt /usr/home/localmode/mode103l/log/logic/number103/digit103_digit103m4_2013050210.txt... (4 Replies)
Discussion started by: ooilinlove
4 Replies

5. Shell Programming and Scripting

Sftp : not able to print the echo statements after the sftp transfer

I had the below sftp script working perfectly but the problem is I am not able to send the echo statements . #!/bin/sh echo "Starting to sftp..." sftp admin@myip << END_SCRIPT cd /remotepath/ lcd /localpath/ mget myfiles*.csv bye END_SCRIPT echo "Sftp successfully." echo echo... (11 Replies)
Discussion started by: scriptscript
11 Replies

6. Shell Programming and Scripting

Shell script to transfer file via SFTP

Hi all, I'm trying to do a script to transfer file between my server and an external server via SFTP protocol. It doesn't use rsa key, but password. When I run the script, it throw back a prompt that request me to put the password. How should I do for automatic login? Pleaes help :( ... (2 Replies)
Discussion started by: Kapom
2 Replies

7. Shell Programming and Scripting

generate logfile in a shell script

Unix Gurus, I have a shell script which has few "echo" statements. I am trying to create a logfile where all the outputs of the echo statement sare stored. I will have to add this as the final step in the existing script so that everytime the script runs, a logfile is generated with all the... (1 Reply)
Discussion started by: shankar1dada
1 Replies

8. 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

9. Shell Programming and Scripting

not showing restore information while run script

Hello, I have the following script to restore file and grep information. However, once it restore file, it showing a lot useless information and different to check which file have the statement "John price $200". Can I not show any information while running script. It only show..when found the... (1 Reply)
Discussion started by: happyv
1 Replies

10. Shell Programming and Scripting

How to transfer files (By using generic script) when using sftp

I have written generic script to transfer files from one machine to other machine(By passing the command line arguments like server name, user name ,location of the files, file names etc) but when i am using sftp, what are the things I have to specify in the code Is it necessary to specify... (0 Replies)
Discussion started by: gsri
0 Replies
Login or Register to Ask a Question