Login Bluehost FTP using Shell Script on Amazon AWS - shell

Facing error in script while login FTP on Bluehost server using Shell Script on Amazon AWS.
I am able to login FTP using SSH successfully but when use Shell script to automate the FTP login it shows error LOGIN FAILED.
#!/bin/sh
HOST='HOST IP'
USER='username#domainname.com'
PASSWD='password'
ftp -inv $HOST << EOT
user $USER $PASSWD
EOT
exit 0
Below is the result:
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 1 of 50 allowed.
220-Local time is now 04:11. Server port: 21.
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
Remote system type is UNIX.
Using binary mode to transfer files.
331 User username#domainname.com_ OK. Password required
530 Login authentication failed
Login failed.
221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
221 Logout.

Use "quote USER" and "quote PASS" in your script
#!/bin/sh
HOST='HOST IP'
USER='username#domainname.com'
PASSWD='password'
ftp -inv $HOST << EOT
quote USER $LOGIN
quote PASS $PASSWORD
EOT
exit 0
i hope help you

This issue may be unique to BlueHost.
For years I had been successfully using a BASH script with a number of hosting providers for logging in and uploading changes to my SpamAssassin config file. After moving to BlueHost, the script failed, stalled at the password entry prompt, and eventually timed out with a login failure.
The script failed every time even though I was able to successfully login by manually initiating an FTP session and typing/answering the login prompts from a CLI terminal window.
I found the BlueHost password prompt did not like my script password which included a "$" dollar sign as part of the password. The "$" dollar sign embedded in the password was not being passed to the FTP password prompt even when the $PASSWORD variable was quoted as "$PASSWORD". Changing the password to replace the "$" dollar sign character with another character allowed the script to successfully login and upload.

Related

Windows FTP login using "user" command in script fails

I have a simple ftp script file to upload a file to a server.
Script.txt contains:
open ftp.host.com
user Fred PASSword
send c:\hotsheet.dat
disconnect
quit
The cmd line is
Ftp -s:Script.txt
It starts processing correctly but the login fails. I think it is using all lowercase for my password.
The Windows ftp has two login modes. In the default one (the one you are using), it tries to login automatically once the open command is issued and reads the credentials from the script. So the script would have to look like:
open example.com
username
password
send c:\hotsheet.dat
disconnect
quit
So what is happening with your script is that the user Fred PASSword is used as a username as a whole (and similarly the send c:\hotsheet.dat is used as a password). You can tell that, if you add -d (debug) switch:
---> USER user Fred PASSword
331 Please, specify the password.
---> PASS send c:\hotsheet.dat
530 Login incorrect.
Login failed.
Or you can prevent the automatic login with -n switch:
ftp -s:Script.txt -n
And then explicitly login using the user command, just as your script is doing.

FTP from terminal if username contains #?

How do you connect to an FTP server from the command line if your username is your email address? Usually I login in like this:
ftp username#ftp.server.com
But if my username is an email address, it doesn't work:
ftp myname#mysite.com#ftp.server.com
I've tried using an escape character \#, and putting the username in quotes. Neither work. I looked in the man pages and searched Google to no avail.
Take a look to man ftp and you shoud use $HOME/.netrc file containing the username. See:
user User [Password] [Account] Identifies the local user (User)
to the remote FTP server. If the Password or Account parameter is not specified and the remote server requires it, the ftp command prompts for the password or account locally. If the Account parameter is required, the ftp command sends it to the remote server after the remote login process completes.

Giving the user password in a script

I had made a script that allows ftp login.But I dont know how to add password for the user
#!/bin/bash
if grep -q $1 "/opt/proftpd.conf"; then
echo "$1 is an ftp user"
HOST='192.168.1.212'
USER=''$1''
FILE=''$2''
ftp -n -v $HOST <<END_SCRIPT
quote USER $USER
put $FILE
quit
END_SCRIPT
ls -la /home/$1
exit 0
else
echo "$1 is not an ftp user"
fi
exit 0
How can I add the user password for ftpuser?...
An example:
#!/bin/bash
ftp_host="192.168.1.212"
ftp_user="$1"
ftp_file="$2"
read -s -p "Enter password for user ${ftp_user}: " ftp_pass
ftp -n -v ${ftp_host} << EOF
quote USER ${ftp_user}
quote pass ${ftp_pass}
bin
put ${ftp_file}
EOF
It depends on the ftp version.
Sometime versions allow to give user and password together with host name:
ftp://[user[:password]#]host[:port]/path
There are also two ftp commands that allow to pass credentials (man ftp):
account [passwd]
Supply a supplemental password required by a remote system
for access to resources once a login has been successfully
completed. If no argument is included, the user will be
prompted for an account password in a non-echoing input mode.
user user-name [password] [account]
Identify yourself to the remote FTP server. If the password
is not specified and the server requires it, ftp will prompt
the user for it (after disabling local echo). If an account
field is not specified, and the FTP server requires it, the
user will be prompted for it. If an account field is speci-
fied, an account command will be relayed to the remote server
after the login sequence is completed if the remote server
did not require it for logging in. Unless ftp is invoked
with "auto-login" disabled, this process is done automati-
cally on initial connection to the FTP server.

Write a Script to respond to prompts with specified text

I am writing a script which will automatically capture a screenshot and trigger iSight to take a still photo when the script is run, then upload it to FTP. Everything is perfect other then one thing, my FTP requires a username and password to be entered when prompted (after both images are captured)
heres what I have:
echo “GOLDENEYE ACTIVATED….”
screencapture -x screen.jpg
imagesnap Mugshot.jpg
ftp <YourServerHere>
Terminal Responds:
Connected to <YourServerHere>
Now, Username must be entered when this appears:
220 Welcome to <ServerDomain>, FTP server standing by ...
Name (<ServerName>.<DomainName>.:<Name>): <Type UserName Here - Hit Enter>
And, Password will be entered upon successful entry of a valid Username:
331 Hello <UserName>, your FTP account password is required:
Password: <Type Your Password Here - Hit Enter>
After the proper credentials are entered, Terminal will respond:
230-Login successful, your current directory is /
230 0 Kbytes used (0%) - authorized: 7340032 Kb
Remote system type is UNIX.
Using binary mode to transfer files.
And, to upload the images:
ftp> put /Mugshot.jpeg
ftp> put /Screen.jpeg
I am attempting to Automate the username and password entry after the prompts are given, in order for the script to be successful
the text would be, "username" and "password" to be entered after the each prompt is given.
i am completely new to terminal and scripts, just playing around in my spare time, please excuse anything which is incorrect here, thanks for ANY help and education!
A general solution is the expect command.
But for your task, it's an overkill.
The ftp reads commands from a standard input.
So just do:
ftp -n < command.txt
The -n prevents the automatic prompts for username/password. We provide these explicitly using the user command below.
The commands.txt file will look like:
open host
user user password
put /path
bye

cannot login to the ftp server

Anyone has an idea what will be the problem?
#!/bin/bash -x
HOST='192.163.3.3'
USER='ftpuser'
PASSWD='apple'
Logfile=a.log
while :; do
ftp -n -p -v $HOST < example.script >> a.log
grep -qF "Connected" a.log &&
grep -qF "File successfully transferred" a.log && break
done
quote USER $USER
quote PASS $PASSWD
example.script contains
put example.txt
after running it gives
grep: a.log: No such file or directory
grep: a.log: No such file or directory
.
.
example.script and the created a.log is on /home directory
the a.log contains
Connected to 192.163.3.3.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 9 of 50 allowed.
220-Local time is now 14:38. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
Remote system type is UNIX.
Using binary mode to transfer files.
local: example.txt remote: example.txt
530 You aren't logged in
Passive mode refused.
221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
221 Logout.
why cant i logged in?
HOST='192.163.3.3'
USER='ftpuser'
PASSWD='apple'
FILE='example.txt'
Logfile=a.log
ftp -n -p -v $HOST << SCRIPT_END >> a.log
quote USER $USER
quote PASS $PASSWD
put $FILE
SCRIPT_END
with this it works but why? what will be the difference?
Your FTP daemon is refusing passive mode file transfers (PASV command). You have to enable passive mode transfers on Pure-FTPd. This site has nice tutorial on how to do it:
Getting passive FTP connections to work through a firewall properly - scroll down to section Setting up the FTP Server (Pure-FTPD).
I usually find creating a netrc file and using that to at least start my FTP session gets me around a lot of issues with scripting an ftp session. Most ftp programs give you the option of using an alternate netrc file, so you don't need to setup one at $HOME/.netrc.
I believe you just need a one liner like this:
machine 192.163.3.3 login ftpuser password apple
Unfortunately, I can't test it because I don't have ftp setup anywhere. Everything here is scp/ssh/sftp. Here's an example .netrc file.
It is complaining about being in passive mode, I would remove the -p from the command or allow passive FTP.
-p
Use passive mode for data transfers. Allows use of ftp in environments where a firewall prevents connections from the outside world back to the client machine. Requires that the ftp server support the PASV command. This is the default now for all clients (ftp and pftp) due to security concerns using the PORT transfer mode. The flag is kept for compatibility only and has no effect anymore.

Resources