upload files to remote host over lftp - bash

I have this script to upload and delete files on my remote host:
#!/bin/bash
echo Starting Website upload ...
echo This may take some time depending on your internet connection ...
echo Waiting for remote connnection ...
lftp -u server121.web-hosting.com << ftpEOF
prompt
cd public_html
delete index.html
cd images
mdelete *.jpg
cd ..
lcd /Applications/PlexEmail/streamnet/
put index.html
lcd images
cd images
mput *.jpg
bye
ftpEOF
echo Website upload successfull ...
After upgrading my Mac to High Sierra 10.13, the ftp command no longer exists.
Any ideas on how to get this to work with lftp?

Related

Uploading current day's backup instead of all files via Cron jobs

I have a VPS running on Centos 7, and created a cron job to dump my database (Sql 8.0) and to create a tar to backup my entire site's files and this goes on everyday
I want to create another bash / cron job to connect to my backup server and upload those backup files stored on my VPS.
The problem is, I can't get it to upload only the newest files, not the entire files as there will be 7 backups every week.
I want it to only upload today's files, not all available files.
Should I use rsync ?
Here is my bash so far:
#!/bin/sh
USERNAME="ftp user"
PASSWORD="ftp password"
SERVER="IP or domain"
# local directory to pickup *.tar.gz file
FILE="/path/"
# remote server directory to upload backup
BACKUPDIR="/pro/backup/sql"
# login to remote server
ftp -n -i $SERVER <<EOF
user $USERNAME $PASSWORD
cd $BACKUPDIR
mput $FILE/*.tar.gz
quit
EOF
You can use find with -ctime to search for .tar.gz files changed in the last 7 days and then loop on the results, ftping each. Using this logic with your existing solution:
#!/bin/sh
USERNAME="ftp user"
PASSWORD="ftp password"
SERVER="IP or domain"
# local directory to pickup *.tar.gz file
FILE="/path/"
# remote server directory to upload backup
BACKUPDIR="/pro/backup/sql"
while read fil;
do
# login to remote server
ftp -n -i $SERVER <<EOF
user $USERNAME $PASSWORD
cd $BACKUPDIR
mput "$FILE/$fil"
quit
EOF
done < "$(find $FILE -ctime -7 -name "*.tar.gz")"

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.

How to run multi commands in one sh file?

I have a mac os and
my question is about 'How to run multi commands in one sh file?', like this :
#!/bin/bash
ftp
open domain.com
user
pass
cd /public_html/test_folder
lcd /Users/mac/downloads
mput file
a
This commands for :
open ftp
connect to my website
enter user name
enter password
cd << for open folder in my website
lcd << open folder in my computer
mput << upload file from my computer
a << for question in ftp for file type or something like this
I add && in end each line but no work he start and stop in command line number 2
I'm sorry for my bad language :(
Use lftp, very good in ftp scripting, when you require reconnect+continue file transfer, ssh/scp transfer, etc.
It should be similar to this:
#!/bin/bash
## note: mput: -c (retry+continue); run: lftp -c 'help mput' to see help
lftp -c 'mput -c -O ftp://name:passd#server.com/path/ file1.txt file2.txt'
Alternatively, you can write lftp scripts, example (note: mirror -R = upload):
#!/usr/bin/lftp -f
open ftp://ftp.server.com
user name passwd
cd /remote/path
lcd /local/path
mirror -R folder

Cannot upload files and folders in directory via FTP in batch script

I have a few folders I wish to upload to a server via FTP.
This is the folder structure:
build >
fonts >
- font1.ttf
- font2.ttf
images >
- img1.png
- img2.png
javascripts >
- script.js
stylesheets >
- style.css
index.html
I have fileup.bat:
#echo off
echo user USERNAME> ftpcmd.dat
echo PASSWORD>> ftpcmd.dat
echo prompt>> ftpcmd.dat
echo cd %1>> ftpcmd.dat
echo lcd %2>>ftpcmd.dat
echo mput *.*>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat 123.456.78.9
del ftpcmd.dat
pause
And run_ftp.bat which is a single line, public_html/ is the destination of the files on the server and C:\Web\build is where the files are located on my PC:
fileup public_html/ C:\Web\build
The run_ftp.bat is located in C:\Web and fileup.bat is in C:\Windows so it appears in the PATH and I can run fileup in cmd.
When I run run_ftp.bat the only files that get uploaded to the server are in the root of /build, so only index.html is uploaded. The console logs: Error opening local file fonts. for each of the folders inside /build.
Here's the log:
230 OK. Current restricted directory is /
ftp> prompt
Interactive mode Off .
ftp> cd public_html/
250 OK. Current directory is /public_html
ftp> lcd C:\Web\build
Local directory now C:\Web\build.
ftp> mput *.*
Error opening local file fonts.
Error opening local file images.
200 PORT command successful
150 Connecting to port 57128
226-File successfully transferred
226 0.142 seconds (measured here), 1.78 Mbytes per second
ftp: 265174 bytes sent in 0.07Seconds 3682.97Kbytes/sec.
Error opening local file javascripts.
Error opening local file stylesheets.
200 PORT command successful
150 Connecting to port 57129
226-File successfully transferred
226 0.033 seconds (measured here), 36.90 Kbytes per second
ftp: 1229 bytes sent in 0.01Seconds 102.42Kbytes/sec.
ftp> quit
221-Goodbye. You uploaded 261 and downloaded 0 kbytes.
221 Logout.
Press any key to continue . . .
None of the files are folders inside the build folder are in use when I run the .bat file, I'm a bit stumped why none of the folders are being uploaded. I've tried replacing bin with ascii but it does nothing.
Windows command-line ftp.exe client does not support recursive operations.
You have to use a 3rd-party FTP client.
For example with WinSCP you can use:
winscp.com /log=ftp.log /command ^
"open ftp://USERNAME:PASSWORD#ftp.example.com/" ^
"mput ""%2\*"" ""%1""" ^
"exit"
There's a guide for converting Windows ftp.exe script to WinSCP script. Though easier is to have WinSCP GUI generate the script or batch file for you.
(I'm the author of WinSCP)

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

Resources