Solved

how to sftp files

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Utilizing an array to gracefully append to a list of EmailAddresses
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

12 Experts available now in Live!

Get 1:1 Help Now