Failure of sftp send to log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Failure of sftp send to log file
# 1  
Old 11-20-2016
Hammer & Screwdriver Failure of sftp send to log file

I want to transfer all details of sftp connection into a log file and spawn sftp $PCMSu@$FTP_LOC >> log_file is not working for me. Please suggest how to send the data to a log file that has all information if sftp connection is successful or not?

Script that I am using:
Code:
#!/usr/bin/expect
spawn sftp $PCMSu@$FTP_LOC
expect "password:"
send "$PCMSp\n"
expect "sftp>"
send "cd /batchfiles/aspect/\n"
expect "sftp>"
send "put /$PCMS_OUT/qsdaily.dta\n"
expect "sftp>"
send "exit\n"
interact

Please help me how to generate failure log file using expect package (above script) to track if connection is done successfully?

Last edited by Scrutinizer; 11-20-2016 at 12:09 PM.. Reason: code tags
# 2  
Old 11-20-2016
Have you thought about using ssh keys instead of using expect with username password ?
# 3  
Old 11-20-2016
Not knowing WHAT "is not working for me" we can give only very generic advice.
Why don't you use "public key authentication" and a batchfile (-b option)?
# 4  
Old 11-20-2016
Sir, I want to know if sftp connection fails and we want to this error message in log file. How can I get this? I have tried using below script but it wouldn't work:
Code:
#!/usr/bin/expect spawn sftp $PCMSu@$FTP_LOC 2>> log_error_file expect "password:" send "$PCMSp\n" expect "sftp>" send "cd /batchfiles/aspect/\n" expect "sftp>" send "put /$PCMS_OUT/qsdaily.dta\n" expect "sftp>" send "exit\n" interact

Please share how can I check if sftp connection is done successfully or not? is there any way by using that I can check for error if connection lost or not established?

---------- Post updated at 01:19 PM ---------- Previous update was at 01:18 PM ----------

As per my understanding, a batchfile (-b option) is used to send the long file using sftp. Please correct me if I am wrong?

Last edited by Scrutinizer; 11-20-2016 at 04:20 PM.. Reason: code tags
# 5  
Old 11-20-2016
If you get "public key authentication" configured, you could drop expect also simply use rcp with errors redirected to the log file like this:

Code:
rcp /$PCMS_OUT/qsdaily.dta $PCMSu@$FTP_LOC:/batchfiles/aspect/ 2>> log_error_file

# 6  
Old 11-23-2016
Hi
SSH keygen is not an option for us since we dont have access to the remote server so we're looking into using expect to provide password arg for SFTP.
Is there any way to use error redirection to check for the sftp failure error?
I checked this some links but didn't understand about expect_out(buffer).
Please anyone can share the code that send the failure of sftp to failure_log file using error redirection operator? I donot know if it is possible or not using error redirection operator ?
# 7  
Old 11-23-2016
In what sense do you not have access to it? You can sftp to it. You don't have to use a shell to write authorized_keys, sftp may not have append but you can download, upload, move, rename, and even chmod it just fine.

Whatever their security model, they can't have intended for you to use the insecure and third-party expect brute-forcing tool. The stricter they are, the less they'll appreciate you doing so.

All your difficulties are caused by your use of expect. Once you start using sftp the way it's designed for, everything is easy.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Fedora

sftp Unspecified GSS failure Minor code may provide more information No credentials cache found

Hi I have managed on numerous machine to set up sftp not too require a password - i finally have one that does not work and Im at a loss - looked around checked permissions etc The 2 machines Ill call then source and target I need to sftp from source to target (previously the target has... (3 Replies)
Discussion started by: wwwdaryl
3 Replies

2. Shell Programming and Scripting

SFTP Failure

Hi , I need to write a IF condition to know if a SFTP file transfer is successful or not and send email if its failed. `sftp username@servername <<comm1 cd /directory put filename comm1 bye` I use above commands for my connections. So please help me to write a IF statement. ... (0 Replies)
Discussion started by: krishna87
0 Replies

3. Shell Programming and Scripting

[Solved] SFTP error - Couldn't close file: Failure

I am trying to send a file from my 9000 box to a vendor using sftp and I am getting this error: Couldn't close file: Failure Here are the results of my automated script: Connected to yyy.com. sftp> pwd Remote working directory: / sftp> cd xxxxx/yyyyy_TEST/TEST sftp> put FILE FILETEST... (1 Reply)
Discussion started by: nickg
1 Replies

4. Shell Programming and Scripting

Sftp failure

Hello, Sometimes when i execute my shell that makes sftp it gives me this error: Couldn't close file: Failure. What does it mean?, how can i make sure it will do ok?. Bye (2 Replies)
Discussion started by: rubber08
2 Replies

5. Shell Programming and Scripting

Capture all error message in Log file and send the Log file by email

Hi I have a requirement to write a script to capture all errors in a Logfile and send the file in email. If there is any error occurred the subject of email will be ERROR , If there are no error occurred the subject of email will be SUCCESS. So I created a Log file and put the Appropriate... (2 Replies)
Discussion started by: dgmm
2 Replies

6. Shell Programming and Scripting

Send the file through SFTP

abcd1234 (1 Reply)
Discussion started by: B. Bhanumurthy
1 Replies

7. Shell Programming and Scripting

SFTP failure from unix to windows server

Hi, I am having unix server SUNW,Sun-Fire-V245. remote windows server details: Microsoft Windows In my script i am sftp'ing files to the windows server through sftp command. But the problem i am facing is, some files are successfully sftp'd to windows server and for some files sftp is... (0 Replies)
Discussion started by: syamkp
0 Replies

8. UNIX for Dummies Questions & Answers

sftp log file

Hi, I am running this command to sftp a file: sftp -o identityfile=/blah/blah/.ssh/key blah@mass019 > log.log I want to write the output to a log file, but for some reason when the sftp errors out the log file is empty. It seems that it writes to the log only if the connection is... (2 Replies)
Discussion started by: queenie680
2 Replies

9. Solaris

is the MASF agent send traps on IPMP failure?

who is responsible for sending traps if in the IPMP group one nic is failed? is it something that we need to configure manualy or it's automatic configured when u install the masf agent? (solaris 10, on Netra210, masf 1.5.3) (0 Replies)
Discussion started by: shaybery
0 Replies

10. 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
Login or Register to Ask a Question