Jump to content

Need Assistance - Linux Terminal (Upload file to FTP site) for script

Joshndroid
Go to solution Solved by Joshndroid,

The FTP server has to be running /something/ as the operating system. You won't be able to use rsync with your ftp account, but if you have an SSH account, you can use rsync.

 

sorry for some reason i never got the notification for the reply in the thread even though i follow it, weird :blink:

 

anyway. I managed to get what i wanted using curl; it is however a bit weird ill post it

 

I can't have any other access than FTP due to the hosting site, so had to work with what i had

 

NOTE - user and passwrd are not variables i obviously aint going to share them or my server lol

#!/bin/bash    cd /media/joshndroid/ubuntufiles/android/Temasek Roms/Untested/                        LT03WIFICMVERSION=$(grep ro.cm.version ~/temasource/out/target/product/lt03wifi/system/build.prop | cut -d= -f2) &&LT03WIFITMVERSION=$(grep temasek_version_default ~/temasource/packages/apps/Settings/res/values/cr_strings.xml | cut -dV -f2 | cut -d"<" -f1) &&LT03WIFIBUILDFILE=cm-${LT03WIFICMVERSION}-${LT03WIFITMVERSION} &&curl -T "$LT03WIFIBUILDFILE.zip" -u [USER]:[PSWRD] ftp://site.com/Temasek\ Roms/Untested/"$LT03WIFIBUILDFILE.zip"

                        

 

Hello to all the programmers lurking within the site. I have been having a little issue with a script that I have been creating for my android stuff. I have a method at the moment where I'm using lftp to sync (upload) files within a folder to my hosting ftp server. This is all being created via terminal at the moment so i can run minimal command and have my build box build and upload my android rom to the server, it is great for use while im out of the house or at work so i can have most of the work done while im busy.

 

I have found through much searching that lftp is very picky when it comes to variables. I have tried to search as much as i can and come up with my own solution but what i am trying just doesnt seem to work due to the way lftp accepts commands strictly. 

 

Essentially i was wondering if i could get some ideas or assistance to get a file uploading from my local machine to the remote server?

 

Here is the portion of code I have written thus far

 

#check for file creation here   echo "Checking for mako build completion"   cd ~/temasource/out/target/product/mako/   MAKOCMVERSION=$(grep ro.cm.version ~/temasource/out/target/product/mako/system/build.prop | cut -d= -f2)   file="cm-$MAKOCMVERSION.zip"      if [ -f "$file" ]thenecho "$file found"cd ~/temasource/ echo "Build Process completed successfully"echo "Now to cp rom zip to local untested folder"echo "This will also rename the zip with version number"MAKOCMVERSION=$(grep ro.cm.version ~/temasource/out/target/product/mako/system/build.prop | cut -d= -f2)MAKOTMVERSION=$(grep temasek_version_default ~/temasource/packages/apps/Settings/res/values/cr_strings.xml | cut -dV -f2 | cut -d"<" -f1)MAKOBUILDFILE=cm-$MAKOCMVERSION-$MAKOTMVERSIONcp ~/temasource/out/target/product/mako/cm-$MAKOCMVERSION.zip ~/Untested/$MAKOBUILDFILE.zipecho "Uploading untested folder to servers"echo "WARNING!"echo "This will overwrite all files on remote server"echo "You have 10 seconds to stop this"sleep 10#Mirror the untested roms to the untested folder structure on servercd ~/Untested/lftp -u {USER},{PASSWORD} ftp://server.com -e 'set net:timeout 10; mirror --verbose --reverse --only-newer ~/LOCAL /REMOTE; exit' cd ~/temasource/echo "Script will now exit"        #Need to exit the script text file first then the scriptelseecho "$file not found"cd ~/temasource/echo "Build has failed"echo "Check the log text file for issue"echo "Script will now exit"           fi

That was my original setup so far, but i obviously want to be able to do it just a single zip at a time. so i had come up with inserting this at the lftp line

lftp -u {USER},{PASSWORD} ftp://server.com -e "set net:timeout 10; put -O /REMOTE/ /LOCAL/$MAKOBUILDFILE.zip; exit"

Im specifically concerned with the $MAKOBUILDFILE.zip section as this is generated each time as you can see, it will change so i cant do a static entry here, which is causing all my issues and this does not work due to the way lftp works as far as im aware so I'm stuck at what i should do to fix it or whether i can substitute with another package or whatever for ftp that will give me the same result and accept variables while being via command line so i can use it in a script.

Cheers.

Link to comment
Share on other sites

Link to post
Share on other sites

Just to make sure I understand correctly, this is the line giving you trouble, correct?

 

lftp -u {USER},{PASSWORD} ftp://server.com -e "set net:timeout 10; put -O /REMOTE/ /LOCAL/$MAKOBUILDFILE.zip; exit"
Is {USER},{PASSWORD} just a placeholder for the code snippet you posted here, or are they

actual variables? Because if they're variables, you've forgotten the almighty dollar sign.

 

lftp -u ${USER},${PASSWORD} ftp://server.com -e "set net:timeout 10; put -O /REMOTE/ /LOCAL/$MAKOBUILDFILE.zip; exit"
Also, I would recommend using braces when concatenating strings inside double quotes. Yes,

when you're concatenating a variable with an extension like so:

 

"$MAKOBUILDFILE.zip"
that'll work because the period will break the variable name, but I've found it good

practice to use braces so that I don't forget them when they're required, as in this

exampple

"${MAKOBUILDFILE}SOMEMORECHARACTERS"
If you leave them out in that case, bash will try to access variable MAKOBUILDFILESOMEMORECHARACTERS,

which will yield undesired results usually. I don't think that's what's causing your

issues, but I just noticed it and thought I'd mention it because I've duped myself

on a few occasions with this. ;)

Anyway, I have a bash script which uploads a picture to my FTP server as well, and

the lftp line is as follows:

 

lftp -e "put ${filepath}; bye" -u "${user},${pass}" "${server}/${target_dir}"
However, it might be that you need to adjust your ~/.lftp/rc file. For my server

I have needed to put this in there:

 

set ssl:check-hostname noset ssl:verify-certificate noset ftp:ssl-allow false
Depending on your server's FTP config, this might obviously differ for you. But

for me, this combo works without issues.

EDIT:

Alternatively, might SSH be an option via the scp command?

Edited by alpenwasser

BUILD LOGS: HELIOS - Latest Update: 2015-SEP-06 ::: ZEUS - BOTW 2013-JUN-28 ::: APOLLO - Complete: 2014-MAY-10
OTHER STUFF: Cable Lacing Tutorial ::: What Is ZFS? ::: mincss Primer ::: LSI RAID Card Flashing Tutorial
FORUM INFO: Community Standards ::: The Moderating Team ::: 10TB+ Storage Showoff Topic

Link to comment
Share on other sites

Link to post
Share on other sites

Use SCP or rsync (rsync is probably your best bet because it can pickup where it left off).

 

FTP is a terrible, terrible program that's antiquated and insecure.

--Neil Hanlon

Operations Engineer

Link to comment
Share on other sites

Link to post
Share on other sites

Use SCP or rsync (rsync is probably your best bet because it can pickup where it left off).

 

FTP is a terrible, terrible program that's antiquated and insecure.

 

been reading up on rsync and apparently it doesnt work for ftp servers, so what about using curl?

Link to comment
Share on other sites

Link to post
Share on other sites

The FTP server has to be running /something/ as the operating system. You won't be able to use rsync with your ftp account, but if you have an SSH account, you can use rsync.

--Neil Hanlon

Operations Engineer

Link to comment
Share on other sites

Link to post
Share on other sites

The FTP server has to be running /something/ as the operating system. You won't be able to use rsync with your ftp account, but if you have an SSH account, you can use rsync.

 

sorry for some reason i never got the notification for the reply in the thread even though i follow it, weird :blink:

 

anyway. I managed to get what i wanted using curl; it is however a bit weird ill post it

 

I can't have any other access than FTP due to the hosting site, so had to work with what i had

 

NOTE - user and passwrd are not variables i obviously aint going to share them or my server lol

#!/bin/bash    cd /media/joshndroid/ubuntufiles/android/Temasek Roms/Untested/                        LT03WIFICMVERSION=$(grep ro.cm.version ~/temasource/out/target/product/lt03wifi/system/build.prop | cut -d= -f2) &&LT03WIFITMVERSION=$(grep temasek_version_default ~/temasource/packages/apps/Settings/res/values/cr_strings.xml | cut -dV -f2 | cut -d"<" -f1) &&LT03WIFIBUILDFILE=cm-${LT03WIFICMVERSION}-${LT03WIFITMVERSION} &&curl -T "$LT03WIFIBUILDFILE.zip" -u [USER]:[PSWRD] ftp://site.com/Temasek\ Roms/Untested/"$LT03WIFIBUILDFILE.zip"

                        

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×