Solved

how to sftp files

Posted on 2014-10-28
3
172 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 …
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 …
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.

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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now