Solved

Create shell script to sftp files from unix to windows

Posted on 2013-06-05
4
3,798 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 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found listed in my profile here: http:…
Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

707 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