?
Solved

Create shell script to sftp files from unix to windows

Posted on 2013-06-05
4
Medium Priority
?
4,005 Views
Last Modified: 2013-06-07
I need to transfer a txt file that is created on UNIX box to WINDOWS server using SFTP.  Anyone post a program for that by using UNIX shell scripting.
0
Comment
Question by:Lee R Liddick Jr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 15

Assisted Solution

by:achaldave
achaldave earned 200 total points
ID: 39223128
I assume your UNIX box is your sftp server too. if so you can install winscp on your windows box and use scripting on windows side to transfer files

http://winscp.net/eng/docs/commandline
0
 

Author Comment

by:Lee R Liddick Jr
ID: 39223214
I have no access to the WINDOWS SERVER box except the one shared folder.
0
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 1600 total points
ID: 39223266
If you can mount the shared folder on the Unix box, then just copy "cp" the file to that mount.

Otherwise you may need to make sure "sftp" daemon is executing on the WinDoze server and use "expect" script to make the transfer.

Here is an example:
#!/usr/bin/expect
######################################################
#  sendFile.ex
#
#  About:  This script is used to login to remote
#          server and send text file
#
######################################################
if {[llength $argv] == 0} {
  puts "!Error: Missing parameters sftp-rfc {-index|#}"
  exit 1
}
set timeout 600
set user   [lindex $argv 0]
set pass   [lindex $argv 1]
set regdir [lindex $argv 2]
set locfil [lindex $argv 3]

spawn date
expect "==>"   ##<<-- You set the server prompt here ##
spawn sftp $user@remote.windoze.com

expect { default {exit 1}
        "password:"
}
send "$pass\n"
expect {
        default {exit 1}
        "sftp>"
}
send "cd $regdir\n"
expect { default {exit 1}
        "sftp>"
}
send "pwd\n"
expect { default {exit 1}
        "sftp>"
}
send "put $locfil\n"
expect { default {exit 1}
        "sftp>"
}
send "bye\n"
exit 0

Open in new window

:p
0
 
LVL 27

Assisted Solution

by:skullnobrains
skullnobrains earned 200 total points
ID: 39228698
given your previous comment, i assume you have access to a windows share so this is unrelated to sftp.

either mount the windows share using samba (smbmount command to start with and potentially stick a line in your fstab to make the mount permanent), or use smbcp http://code.google.com/p/smbcp/downloads/list
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question