Solved

Create shell script to sftp files from unix to windows

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

831 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