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?
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:
Unfortunately, I can’t test it because I don’t have ftp setup anywhere. Everything here is
scp/ssh/sftp. Here’s an example.netrcfile.