Sponsored Content
Top Forums Shell Programming and Scripting help to upload multiple files through SFTP Post 302507482 by kulbhushan on Thursday 24th of March 2011 03:00:42 AM
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
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
PIDOF(8)						Linux System Administrator's Manual						  PIDOF(8)

NAME
pidof -- find the process ID of a running program. SYNOPSIS
pidof [-s] [-x] [-o omitpid] [-o omitpid..] program [program..] DESCRIPTION
Pidof finds the process id's (pids) of the named programs. It prints those id's on the standard output. This program is on some systems used in run-level change scripts, especially when the system has a System-V like rc structure. In that case these scripts are located in /etc/rc?.d, where ? is the runlevel. If the system has a start-stop-daemon (8) program that should be used instead. OPTIONS
-s Single shot - this instructs the program to only return one pid. -x Scripts too - this causes the program to also return process id's of shells running the named scripts. -o Tells pidof to omit processes with that process id. The special pid %PPID can be used to name the parent process of the pidof pro- gram, in other words the calling shell or shell script. NOTES
pidof is simply a (symbolic) link to the killall5 program, which should also be located in /sbin. When pidof is invoked with a full pathname to the program it should find the pid of, it is reasonably safe. Otherwise it is possible that it returns pids of running programs that happen to have the same name as the program you're after but are actually other programs. SEE ALSO
shutdown(8), init(8), halt(8), reboot(8) AUTHOR
Miquel van Smoorenburg, miquels@cistron.nl 01 Sep 1998 PIDOF(8)
All times are GMT -4. The time now is 09:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy