Solved

how to sftp files

Posted on 2014-10-28
3
177 Views
Last Modified: 2014-10-29
Hi everyone,
first time transferring files with sftp: )
Working with an outside company to get some files over to them on a daily basis.
Requirement is to sftp files from our server  to the customers sftp server.
Then archive the files on our server in a tar ball with time date stamp. Still need help with this.

To sftp to the customers server is:
sftp username@123.456.789.123
SSH Server supporting SFTP and SCP
Connected to 123.456.789.123
sftp> ls
Inbox

Basically it's an sftp server with an Inbox only. Once files are sent to the Inbox, it moves the files to the required directory based on file type. So I just have to get the files to their Inbox.

Here's how I started the script, it does work, just wanted your thoughts.

#!/usr/bin/expect
spawn /usr/bin/sftp username@123.456.789.123
#sleep 5
expect "sftp>"
send "mput /directory1/*.*\r"
expect "sftp>"
send "mput /directory2/*.*\r"
expect "sftp>"
send "mput /directory3/*\r"
expect "sftp>"
send "mput /directory4/*\r"
expect "sftp>"
send "mput /directory5/*\r"
expect "sftp>"
send "mput /directory6/*\r"
send "quit \r"

Hope this explains it clearly enough. Thank you!
0
Comment
Question by:Peter Kuczynski
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 500 total points
ID: 40409507
Seems ok.
You may want to replace the "\r"s with "\n"s?
and:
send "bye\n"
instead of quit
And, what about the password?:
expect {
        default {exit 1}
        "password:"
}
send "$pass\n"

Open in new window

0
 
LVL 1

Author Comment

by:Peter Kuczynski
ID: 40409592
Thanks Mike, it uses public keys for authentication so that's not an issue.
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 40410722
Then you are good to go!
:p
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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