help to upload multiple files through SFTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help to upload multiple files through SFTP
# 1  
Old 03-24-2011
help to upload multiple files through SFTP

Hi Experts,

Please help me to write the expect script for uploading multiple files in one shot . Below is my program that I have written.
Code:
#!/usr/local/bin/expect -f #/home/kulbhushan/sftp_prog.sh
# procedure to attempt connecting; result 0 if OK, 1 otherwise
 proc connect {passw} {
  expect {
    "Password:" { 
        send "$passw\r"
        expect {
           "sftp*" {
                return 0
            }  
        }
     }
  }
  # timed out
  return 1
 }

 #read the input parameters
 set user [lindex $argv 0]
 set passw [lindex $argv 1]
 set host [lindex $argv 2]
 set location [lindex $argv 3]
 set file1 [lindex $argv 4]

 
 #puts "Argument data:\n";
 #puts "user: $kpatil";
 #puts "passw: $patil";
 #puts "host: $helios";
 #puts "location: $/groups/YBL";
 #puts "file1: $TaskSheet.xls";


 #check if all were provided
 if { $user == "" || $passw == "" || $host == "" || $location == "" || $file1 == "" }  {
   puts "Usage: <user> <passw> <host> <location> <file1 to send>\n"
   exit 1
 }

#sftp to specified host and send the files
 spawn sftp $user@$host
 
 set rez [connect $passw]
 if { $rez == 0 } {
   send "cd $location\r"
   set timeout -1
   send "put $file1\r"
   send "quit\r"
   expect eof
   exit 0
 }
 puts "\nError connecting to server: $host, user: $user and password: $passw!\n"
 exit 1


Last edited by Franklin52; 03-24-2011 at 04:08 AM.. Reason: Please use code tags
# 2  
Old 08-30-2011
Java Just a small Change

Hi,
You have just a small mistake in your Script.
During sftp to a server it will put a message "user@host's password:". So you need a small change.

Code:
expect {
    "Password:" 
#this Should be --> 
expect {
    "*assword:"

Manikanda raj S
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File upload message in SFTP

Hi, Below script is running on AIX 7.1 ( 7100-04-05-1720 version ) server. Recently OpenSSH version installed on server got updated from OpenSSH_6.0p1 to OpenSSH_7.5p1 version. After this update we do not receive any file upload message after put/mput command in SFTP. sftp -b - user@server... (1 Reply)
Discussion started by: Juggernaut
1 Replies

2. Shell Programming and Scripting

SFTP Multiple files

Hi :), I am new to Unix and Shell Script I have a urgent requirement, where i am new to shell script and Unix my requirement is I have a files in a folder like sales-prod-India-details.txt sales-prod-japan-details.txt sales-prod-china-details.txt My SFTP server has ... (3 Replies)
Discussion started by: spradeep86
3 Replies

3. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

4. UNIX for Dummies Questions & Answers

[Solved] ls -l in CentOS 6.4 after upload using sftp

Hi everyone, Something rather interesting just happened to me. I uploaded a file to a server through sftp. I closed the connection and then logged on to the server via ssh. So far so good. When I typed ls -l in the remote server to retrieve a directory listing, the file that was previously... (2 Replies)
Discussion started by: gacanepa
2 Replies

5. Shell Programming and Scripting

Generate file and Upload to SFTP server.

Xperts, My requirement is something like this, I have a sql script which i need to embed in a shell. The sql (oracle) script will generate a .csv file in some Unix directory. the approximate file size is around 10 mb which i need to upload to an sftp server. My concern here is how to make... (5 Replies)
Discussion started by: Showdown
5 Replies

6. Shell Programming and Scripting

Expect Script for SFTP Upload

I am attempting to utilize an expect script (that is called from a parent bash script) to perform a file transfer over sftp. The script works except I cannot catch timeouts. I need to be able to tell in the parent bash script when the expect script has timed out, or completed successfully. It... (3 Replies)
Discussion started by: thaller
3 Replies

7. UNIX for Advanced & Expert Users

chrooted SFTP upload folder

Hi List, I have set up a chrooted SFTP setup following the instructions I found on tech republic: /blog/opensource/chroot-users-with-openssh-an-easier-way-to-confine-users-to-their-home-directories/229 I have successfully got it all working and I can download files when logged in via sftp... (0 Replies)
Discussion started by: landossa
0 Replies

8. Shell Programming and Scripting

upload multiple files

i need a javascript html file for uploading multiple files with abitlity to select many files at a time and a cgi-perl script at the back end on server. (0 Replies)
Discussion started by: raksha.s
0 Replies

9. Shell Programming and Scripting

sftp file upload problem

Hi All, I am trying to upload a text file from HP unix to Windows tectia server using sftp, the text file shows with new line character after upload. For EG : abc.txt file contains 123 456 aftre upload it shows as 123 456 i am using sftp version 2.0 TQ, (4 Replies)
Discussion started by: phani1312
4 Replies

10. UNIX for Dummies Questions & Answers

sftp multiple files and subdirectories

Hi, I'm new to using the sftp command prompt within the unix shell (usually I just use an FTP windows program). I've successfully connected to a remote server from within ssh. I've also been able to copy multiple files using the mget command e.g. mget *.html How do I copy all files,... (3 Replies)
Discussion started by: robbieg
3 Replies
Login or Register to Ask a Question