Solved

how to sftp files

Posted on 2014-10-28
3
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

691 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