Solved

Create shell script to sftp files from unix to windows

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Have you considered what group policies are backwards and forwards compatible? Windows Active Directory servers and clients use group policy templates to deploy sets of policies within your domain. But, there is a catch to deploying policies. The…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now