Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-11-2017, 08:48 AM
|
#1
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Rep: 
|
Cannot sftp into Windows sftp
I am trying to sftp into a Windows sftp to transfer files. I am currently using Expect but I want to have some security. In a bash script I simply have these commands:
sftp username@hostname
cd dir3
lchdir /people/dir/occupation
put *.DAT
I commented each line, one by one to see why it will not execute correctly. What am I doing wrong?
|
|
|
01-11-2017, 08:55 AM
|
#2
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
as you have not stated how you have your set up setup I can only guess.
where are your DAT files located in respect to where your script is located? Does not the sender have to be inside of the directory that has the files to be transferred to another system via ftp when logging in? if your script is not in that same directory then perhaps it is not able to put any DAT files to the other system due to that fact.
Your security comes from the user login process. The who can and cannot login and what they can and cannot access and do within that system they logged into via how the receiving system is setup to allow or not allow whatever user it allowed to log into it via ftp.
lchdir command
Expect ~ a help post for expect on logging in and sending using Expect. It might help.
Last edited by BW-userx; 01-11-2017 at 09:00 AM.
|
|
1 members found this post helpful.
|
01-11-2017, 09:06 AM
|
#3
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,968
|
You say this is a bash script, therefore you can have the start of it be:
Code:
#!/bin/bash
set -xv
This enables verbose output from your script and will show you the results of these commands.
Also, I always state that what you can type in a command line, you can code in a bash script. The reverse is true, which is whatever you code in a bash script you can type in the command line. Therefore you should be able to type those commands cited in your first post, verbatim in the command line. Similarly you can type "set -xv" into the command line to enable verbose output, and then type "set +xv" to turn that back off.
This should help you to debug your script and commands.
If there is more to your script, consider posting it within [code][/code] tags.
|
|
1 members found this post helpful.
|
01-11-2017, 09:16 AM
|
#4
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
I did run the script in verbose mode and I noticed that when the script is ran, it just logs in and the 'sftp>' prompt shows. So I would need to pass commands from the 'sftp' prompt in a script. Is this possible?
Last edited by trickydba; 01-11-2017 at 09:19 AM.
|
|
|
01-11-2017, 09:27 AM
|
#6
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
Quote:
Originally Posted by trickydba
I did run the script in verbose mode and I noticed that when the script is ran, it just logs in and the 'sftp>' prompt shows. So I would need to pass commands from the 'sftp' prompt in a script. Is this possible?
|
I gave you a link to a script that logs in and sends files then exit ftp when done using Except like you stated you are using.
excerpt of that link post
Quote:
test.sh script in which sftp is used which is working fine is as follows
Code:
#!/usr/bin/expect
spawn sftp ftp_dl@10.132.249.50
expect "ftp_dl@10.132.249.50's password:"
send "database123#\n"
expect "sftp>"
send "put ZTE_*201505*\n"
expect "sftp>"
send "bye\n"
exit
~
|
Last edited by BW-userx; 01-11-2017 at 09:30 AM.
|
|
1 members found this post helpful.
|
01-11-2017, 09:37 AM
|
#7
|
Moderator
Registered: Aug 2002
Posts: 26,926
|
I believe the OP wants to switch from expect to bash only since they are using keys. As explained in the previously thread you can create a batch file or by piping your commands.
|
|
1 members found this post helpful.
|
01-11-2017, 09:45 AM
|
#8
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
Quote:
Originally Posted by michaelk
I believe the OP wants to switch from expect to bash only since they are using keys. As explained in the previously thread you can create a batch file or by piping your commands.
|
OIC
in that case in another excerpt from that post I linked to it says this:
Quote:
Note that sftp is specifically designed to prevent you from doing what you are trying to do because it is an extremely bad and insecure method of transferring files. That is why you are forced to use the expect brute-force password injection tool to inject passwords into it brute-force. It would be better to cooperate with the way sftp is designed to work, and use passwordless keys.
|
@ OP
or
Secure FTP using Windows batch script
Last edited by BW-userx; 01-11-2017 at 09:51 AM.
|
|
1 members found this post helpful.
|
01-11-2017, 10:07 AM
|
#9
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
That previous thread I created does work bu this morning I ran into an issue. This is my code:
echo -e "cd DESTFOLDER\nlchdir /location/of/file/*.DAT\n" | sftp -b - username@hostname
I get an error that no such file or directory exists. The code is right, which is why I marked that thread as resolved but I think it might be because I am trying to use a wildcard instead of an exact filename. The reason for this is because the date is appended to the filename daily.
|
|
|
01-11-2017, 10:15 AM
|
#10
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
Quote:
Originally Posted by trickydba
That previous thread I created does work bu this morning I ran into an issue. This is my code:
echo -e "cd DESTFOLDER\nlchdir /location/of/file/*.DAT\n" | sftp -b - username@hostname
I get an error that no such file or directory exists. The code is right, which is why I marked that thread as resolved but I think it might be because I am trying to use a wildcard instead of an exact filename. The reason for this is because the date is appended to the filename daily.
|
is it just one file?
run a find me command before hand
Code:
userx@voider~/testme:>> newfile="$(find ~/testme/ -type f -name "*.dat")"
userx@voider~/testme:>> echo $newfile
/home/userx/testme/3-3-2323.dat
newfile="$(find ~/testme/ -type f -name "*.dat")"
echo -e "cd DESTFOLDER\nlchdir "$newfile"\n" | sftp -b - username@hostname
but is that command needs to be tested.
|
|
1 members found this post helpful.
|
01-11-2017, 10:21 AM
|
#11
|
Moderator
Registered: Aug 2002
Posts: 26,926
|
In addition, your first post commands are not the same as your #9
Code:
echo -e "cd dir3\nlchdir /people/dir/occupation\nput *.DAT" | ...
|
|
1 members found this post helpful.
|
01-11-2017, 12:12 PM
|
#12
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
My issue has been resolved using this code:
echo -e "cd PROD\nlchdir /dir1/dir2/dir3/reports\n put *.DAT" | sftp -b - username@hostname
Thank you everybody for your help!
|
|
|
All times are GMT -5. The time now is 10:43 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|