Linux - NewbieThis 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.
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.
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?
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.
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.
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 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
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.
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.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.