Download files from specific folder in AIX box - ftp

I have an AIX box. I wanted to connect to remote FTP server and download a specified folder "abc".
I have created a script; but it isn't working.
Here is my Code:
#!/bin/sh HOST='ftp.abc.xysz.net' USER='ftp' PASSWD='password' FILE='ababababababababababababab.abab';
ftp $HOST user $USER $PASSWD mget $FILE
quit END_SCRIPT
exit 0
Here is the error I receive when I execute Script..
Anyone has any idea to download the files from remote FTP server. Is there any single command available

Your script doesn't look properly formatted... it would be something like this:
#!/bin/sh
HOST='10.129.151.41'
USER='technicolor'
PASSWD='blueray'
FILE='ababababababababababababab.abab'
ftp -n <<END_SCRIPT
open $HOST
user $USER $PASSWD
get $FILE
quit
END_SCRIPT

Related

Change shell script from ftp to sftp

I have below shell script to get files from ftp server.
I need to change this script to point to same SFTP server ?
Can some one assist to change this script from ftp to sftp?
HOST='some.site.com'
USER='yourid'`enter code here`
PASSWD='yourpw'
FILE='file.txt'
ftp $HOST <<END_SCRIPT
user $USER
$PASSWD
put $FILE
quit
END_SCRIPT
exit 0
It's not so complicated, just use the sftp binary instead of the ftp. The FTP commands stay exactly the same (it's still the FTP protocol, just over an encrypted connection), the user may be specified as a part of the SFTP's host argument:
sftp $USER#$HOST <<EOF
$PASSWD
put $FILE
quit
EOF

How to connect to a ftp server via bash script?

I wrote a bash script for uploading backup files from a server to a ftp server. But I always get an error.
Name (myftpserver:root): Permission denied.
Login failed.
Login with USER first.
Please login with USER and PASS.
Local directory now /backup01
Please login with USER and PASS.
Passive mode refused.
That's my script:
#!/bin/bash
DATE=`date +%Y-%m-%d_%H%M`
LOCAL_BACKUP_DIR="/backup01"
DB_NAME="databasename"
DB_USER="root"
FTP_SERVER="randomIP"
FTP_USERNAME="myname"
FTP_PASSWORT="supersecret"
FTP_UPLOAD_DIR="/home/mydirectory/ftp/upload"
LOG_FILE=/backup01/backup-$DATE.log
mysqldump -u $DB_USER $DB_NAME | gzip > $LOCAL_BACKUP_DIR/$DATE-$DB_NAME.sql.gz
ftp $FTP_SERVER << END_FTP
quote USER $FTP_USERNAME
quote PASS $FTP_PASSWORD
cd $FTP_UPLOAD_DIR
lcd $LOCAL_BACKUP_DIR
put "$DATE-$DB_NAME.sql.gz"
bye
END_FTP
if test $? = 0
then
echo "Database successfully uploaded to the FTP Server!"
echo "Database successfully created and uploaded to the FTP Server!" | mail -s "Backup from $DATE" my.email#whereever.com
else
echo "Error in database upload to Ftp Server" > $LOG_FILE
fi
Maybe someone can help me, because I've tried everything I've found on the internet.
I've made a .netrc file. I configured the vsftpd.conf, enabled passiv mode, enabled user list and I've made a lot of other stuff...
But now I'm having no idea what else I have to do to make this script working the way it should. And I have no idea why it's trying to connect via root...
Maybe there is someone out there who can help.
Thanks in advance.
I use:
ftp -v -n >> /tmp/ftpb.log <<EOF
open $URL
user $USER $PASS
binary
put $FILE
quit
EOF
and works
It's a common staple to use something like this:
$: ftp -vn <<!
> open localhost
> user foo
> put someFile
> quit
> !
> ftp: connect :Connection refused
Not connected.
Not connected.
Not connected.
$: echo $?
0
Unfortunately ftp considers that it successfully reported all problems, so it exits with a happy zero.
Use scp:
if scp "$lcldir/$filename" "$usr/$pw#$svr:$dir/"
then echo "file delivered"
else echo "delivery failed"
fi
If you can't use scp try something like expect, or write something in Perl - some way you can interactively test and confirm each step.
As a last resort, make the here-doc send the file and then pull it back to a tempfile that doesn't already exist locally. If you can successfully cmp file1 file2 afterwards, the send must have worked ok.

Upload sites files and folders via ftp bash

I need a script to upload files of sites with directories to hosting via ftp.
I try to create a script, but it doesn't work. NO files are on the server. Can you help me, please?
My script
#!/bin/bash
HOST='ip_address'
USER='user'
PASSWD='password'
SERVER_FOLDER='/site'
cd /local_folder_with_sites_files
ftp -in <<END_SCRIPT
open $HOST
user $USER $PASSWD
cd $SERVER_FOLDER
mput -r *
close
bye
END_SCRIPT
echo "Upload complete"
exit 0
Output:
directory: not a plain file.
Permission denied.
Passive mode refused.
OS: Ubuntu 16.04 Panel: VestaCP
But when i upload files via filezilla, uploads is complete.
If anybody has a script which uploads files and folders via ftp, please, show me for example.

ksh script to send .jpg to remote server through ftp script

Hello just created a ksh script to ftp .jpg image to a remote server but the images are showing in bad qulity when I send them with the script is there a line I should fix to not alterate the image a deliver the image to the remote server like the original please help, should I add the bin line?
cp -r /path/dir/*.jpg /path/dir
cp -r /path/dir/*.JPG /path/dirREMOTE
USER='xxx'
PASSWORD=xxx'
source_dir='cd /path/images/'
target_dir='cd /images'
ftp -n xxx.xx.xxx.xx <<_FTP
quote USER $USER
quote PASS $PASSWORD
lcd /xxx/xxx/
cd /xxx
mput *.jpg
bye
_FTP
/home/test_scripts/test_script9.sh
/home/test_scripts/test_script7.sh
exit
enter code here

ftp shell script breaks up after the lcd-command

I created a shell script to download several files, all starting with "2014" from an ftp server. I use mget for this and the filename 2014*.
To make sure that the files are saved at the right local place I use lcd before.
It looks like this:
#!/bin/sh
HOST='ftpserver.name.de'
USER='user1'
PASSWD='pw1'
FILE='2014*'
LOCDIR='/home/local/data2014/'
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
lcd $LOCDIR
mget $FILE
quit
END_SCRIPT
exit 0
when I try this, the script just runs:
lx9000: ftp_get.sh
Connected to ftpserver.name.de.
220 FTP-Server: ftpserver.name.de
331 Password required for user1
230 User user1 logged in
Local directory now: /home/local/data2014/
221 Goodbye.
why dose it stop before the downloading proceeds?
Thanks for help!
Try adding:
prompt off
before the mget.

Resources