Sponsored Content
Top Forums Shell Programming and Scripting automate sftp using unix script Post 302178830 by pbrowne on Wednesday 26th of March 2008 11:38:22 AM
Old 03-26-2008
I too am attempting to write a shell script using expect to automate a file transfer from a Windows box to a Sun box.

I have eliminated the -B option and have hard coded all prompts and replies in my expect script and it actually runs via cron however I am only getting a partial download.

Here is the expect script:

Code:
#!/usr/local/bin/expect -f -d
spawn  sftp -v ftplogin@ftpserver
expect "ftplogin@ftpserver's password: "
sleep 7
send "thepassword\r";
expect "sftp>"
send "lcd /tmp\r"
expect "sftp>"
send "get dailyinventory.txt\r"
expect "sftp>"
send "exit\r"

Here is a sample of the log created by the -v option

Code:
spawn sftp -v ftpuser@ftpserver
Connecting to ftpserver...
Sun_SSH_1.1, SSH protocols 1.5/2.0, OpenSSL 0x0090700f
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Rhosts Authentication disabled, originating port will not be trusted.
debug1: ssh_connect: needpriv 0
debug1: Connecting to ftpserver [ftpserver] port 22.
debug1: Connection established.
debug1: identity file /.ssh/id_rsa type -1
debug1: identity file /.ssh/id_dsa type 2
debug1: Remote protocol version 2.0, remote software version WRQReflectionForSecureIT_6.1 Build 21
debug1: no match: WRQReflectionForSecureIT_6.1 Build 21
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-Sun_SSH_1.1
debug1: Failed to acquire GSS-API credentials for any mechanisms (No credentials were supplied, or the credentials were unavailable or inaccessible
mech_dh: Invalid or unknown error
)
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: Peer sent proposed langtags, ctos: 
debug1: Peer sent proposed langtags, stoc: 
debug1: We proposed langtags, ctos: i-default
debug1: We proposed langtags, stoc: i-default
debug1: dh_gen_key: priv key bits set: 131/256
debug1: bits set: 495/1024
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Host 'ftpserver' is known and matches the DSA host key.
debug1: Found key in /.ssh/known_hosts:5
debug1: bits set: 528/1024
debug1: ssh_dss_verify: signature correct
debug1: newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: done: ssh_kex2.
debug1: send SSH2_MSG_SERVICE_REQUEST
debug1: got SSH2_MSG_SERVICE_ACCEPT
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /.ssh/id_rsa
debug1: Trying public key: /.ssh/id_dsa
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
ftpuser@ftpserver's password: 
debug1: Authentication succeeded (password)
debug1: fd 6 setting O_NONBLOCK
debug1: channel 0: new [client-session]
debug1: send channel open 0
debug1: Entering interactive session.
debug1: ssh_session2_setup: id 0
debug1: Sending subsystem: sftp
debug1: channel request 0: subsystem
debug1: channel 0: open confirm rwindow 100000 rmax 32768
sftp> lcd /tmp
sftp> get dailyinventory.txt
Fetching /HOME/dailyinventory.txt to dailyinventory.txt


The problem is that the dailyinventory.txt file download has 16,586 records but the dailyinventory.txt file on the ftpserver has 68,082 records.

Wondering if anyone else has seen this problem w/ partial downloads?

Thanks in advance,

pat
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automate SFTP is not working

Hi All:cool:, i tried to automate SFTP process after passwordless authendication. Stil i am getting error... Can anyone help.... ------------------- sample code below ------------------- sftp -v $mdskk@100.4.4.75 << EOF cd /data mget *.tar.gz bye EOF... (2 Replies)
Discussion started by: senthil_seera
2 Replies

2. AIX

Automate SFTP UNIX to Windows

Hi, Could you please help to solve the below issue... my requirement is automate the SFTP between UNIX and Windows server. I want to get and put some files to UNIX AIX machine(SFTP client) to Windows server(SFTP server). For that, i have generated key pair (private/public) in my AIX machine .... (6 Replies)
Discussion started by: mahiban
6 Replies

3. Shell Programming and Scripting

How to automate sftp in a script to 'get' files.

Hi, I read a couple of forum entries about scripting sftp using the '-b' option, but in my case it still prompts for the password. Does anyone have a sample script for an sftp block to 'get' files from the remote server without prompting for a password? Both the remote and the local servers... (1 Reply)
Discussion started by: ChicagoBlues
1 Replies

4. Shell Programming and Scripting

How to automate sftp without using expect script?

How to automate sftp with out using expect script? My batch file has the password but it is not taking. Please see below. I want to use this sftp connection in a loop for pushing new files in a directory one at a time. Hence I can not use an expect script. bash-2.05$... (5 Replies)
Discussion started by: Tuxidow
5 Replies

5. Shell Programming and Scripting

Unix Shell Script to automate email alert

Hi all, I have a task on my plate which is of high priority. I need an automated email alert that checks FTP notices subdirectory on a daily basis and forwards any word files to a group of people. This word files gets created whenever there is an issue with FTP connectivity. Please help...... (1 Reply)
Discussion started by: stunnerz_84
1 Replies

6. UNIX for Dummies Questions & Answers

automate sftp in sun solaris.

Hi, I'm using Sun Solaris OS. I have configured sftp and can exchange files in command prompt. Now when I try to automate it in ksh script, facing issue as I want to capture the status if the transfer was successful or not. So tried sftp -b and sftp -B option but its not working. The... (3 Replies)
Discussion started by: shinny
3 Replies

7. Shell Programming and Scripting

Using expect to automate sftp

I am trying to use a for loop in my expect cmdFile that I am calling. I want to be able to call either one file name or a series of file names in the working directory (that I won't know the names before hand) and then pass the names to the sftp program. Something like for i in (ls *txt) do (0 Replies)
Discussion started by: vedder191
0 Replies

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

9. UNIX for Dummies Questions & Answers

Automate sftp process using script

Hi, guys, I am trying to automate a sftp process using "expect" method (since the key authentication method is disabled in my company network, there is no helping it). In order to try, I type in the command manually: sftp @ > << EOF >cd >ls -l >EOF >Connecting to @servername password: ... (3 Replies)
Discussion started by: warmboy610
3 Replies

10. Shell Programming and Scripting

Sftp automate

hi, I am trying to automate a file download process using sftp. There is some logic to download files. 1) I need to login to destination server and then go to folder. 2) find list of files and count 3) using list of files I need to eliminate three selective files and download remaining... (1 Reply)
Discussion started by: getmilo
1 Replies
MSVA-QUERY-AGENT(1)					User Contributed Perl Documentation				       MSVA-QUERY-AGENT(1)

NAME
msva-query-agent - query a Monkeysphere Validation Agent SYNOPSIS
msva-query-agent CONTEXT PEER PKC_TYPE [PEER_TYPE] < /path/to/public_key_carrier ABSTRACT
msva-query-agent validates certificates for a given use by querying a running Monkeysphere Validation Agent. USAGE
msva-query-agent reads a certificate from standard input, and posts it to the running Monkeysphere Validation Agent. The return code indicates the validity (as determined by the agent) of the certificate for the specified purpose. The agent's return message (if any) is emitted on stdout. The first three command-line arguments are all required, supplied in order, as follows: CONTEXT Context in which the certificate is being validated (e.g. 'https', 'ssh', 'ike') PEER The name of the intended peer. When validating a certificate for a service, supply the host's full DNS name (e.g. 'foo.example.net') PKC_TYPE The format of public key carrier data provided on standard input (e.g. 'x509der', 'x509pem', 'opensshpubkey', 'rfc4716') The fourth argument is optional: PEER_TYPE The type of peer we are inquiring about (e.g. 'client', 'server') RETURN CODE
If the certificate is valid for the requested peer in the given context, the return code is 0. Otherwise, the return code is 1. ENVIRONMENT VARIABLES
msva-query-agent's behavior is controlled by environment variables: MONKEYSPHERE_VALIDATION_AGENT_SOCKET Socket over which to query the validation agent. If unset, the default value is 'http://127.0.0.1:8901'. MSVA_LOG_LEVEL Log messages about its operation to stderr. MSVA_LOG_LEVEL controls its verbosity, and should be one of (in increasing verbosity): silent, quiet, fatal, error, info, verbose, debug, debug1, debug2, debug3. Default is 'error'. COMMUNICATION PROTOCOL DETAILS
Communications with the Monkeysphere Validation Agent are in the form of JSON requests over plain HTTP. Responses from the agent are also JSON objects. For details on the structure of the requests and responses, please see http://web.monkeysphere.info/validation-agent/protocol SEE ALSO
msva-perl(1), monkeysphere(1), monkeysphere(7) BUGS AND FEEDBACK
Bugs or feature requests for msva-perl and associated tools should be filed with the Monkeysphere project's bug tracker at https://labs.riseup.net/code/projects/monkeysphere/issues/ AUTHORS AND CONTRIBUTORS
Jameson Graef Rollins <jrollins@finestructure.net<gt> Daniel Kahn Gillmor <dkg@fifthhorseman.net<gt> The Monkeysphere Team http://web.monkeysphere.info/ COPYRIGHT AND LICENSE
Copyright AX 2010, Jameson Graef Rollins and others from the Monkeysphere team. msva-query-agent is free software, distributed under the GNU Public License, version 3 or later. perl v5.14.2 2013-04-05 MSVA-QUERY-AGENT(1)
All times are GMT -4. The time now is 08:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy