Solved

Create shell script to sftp files from unix to windows

Posted on 2013-06-05
4
3,498 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
4 Comments
 
LVL 15

Assisted Solution

by:achaldave
achaldave earned 50 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 400 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 50 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

828 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