how to download a folder from bash? - download

I want to download a complete folder from a jenkins project containing many folder
I try with a wget and it works for only one file doing :
wget http://jenkinsmedia:XXXX/job/Lib//280/artifact/tool.rpm
but in the same place there is tool.rpm, there is a folder Test
I want to download the whole folder, is it possible? Or will I have to pick files one by one?

Try using wget -r http://jenkinsmedia:XXXX/job/Lib//280/artifact/
This will create a folder, in that folder it will have a folder job and so on..
use wget -nH --cut-dirs=4 -r http://jenkinsmedia:XXXX/job/Lib//280/artifact/ if you just want to have the folder with the documents

Related

Extract only files with specific extension via bash

For a first time I need to create an .sh for do something. My aim is to unzip a lot of zip folders, so I've wrote the script below:
for zipfiles in /downloads/*.zip; do unzip $zipfiles; done
I can unzip all but I noticed that there are some files with the same name and typing y I can ultimate the process.
There is a way to extract only files with a specific extension, like .docx, instead of the entire zip folder? I'm absolutely sure that there aren't .docx with the same name.
You can specify a pattern:
for zipfiles in /downloads/*.zip; do unzip "$zipfiles" '*.docx'; done
Tested to work with UnZip 6.00.
You can also specify the -x option to exclude.
try this one, it can be useful for your purpose.
for zipfiles in /downloads/*.zip; do unzip -xo "$zipfiles" '*.docx' ; done
by this option overwrite files WITHOUT prompting.

zip created using -jr flags unzipped differently on macOS when double clicking vs running unzip

I am zipping the .xctest file from Plugins folder inside the .app target generated by building my app. I have a build phase script that runs last in my test target to copy this file over. I use the following script to do the zipping:
XCTEST_FILE=${TARGET_BUILD_DIR}/${TARGET_NAME}.xctest
XCTEST_ZIP=${TARGET_BUILD_DIR}/../../${TARGET_NAME}.xctest.zip
zip -jr ${XCTEST_ZIP} ${XCTEST_FILE}
This gives me TestTarget.xctest.zip file. But it unzips differently based on these 2 methods,
unzip TestTarget.xctest.zip
-TestTarget
-CodeResources
-Info.plist
Double clicking TestTarget.xctest.zip in finder
-TestTarget.xctest
--TestTarget
--CodeResources
--Info.plist
Why is unzip going to the innermost node and extracting all the files? I want the unzip command to give me the .xctest directory. I tried renaming the zip file to TestTarget.zip and it still behaves similarly.
I was initially zipping using zip -r ${XCTEST_ZIP} ${XCTEST_FILE}, but the problem with this was it would retain the entire folder structure from root (\) when I double clicked to unzip the file. A post recommend using the -j flag instead of -r. But just -j led to no zip file being generated. Another comment recommend -jr which created a zip that generated output I expected when double clicking it. But I guess the unzip command does stuff differently.
Similar Question: MacOs zip file - different result when double click and running unzip command
The cause for error here was very different,
The problem was when the file was created. It was not related to MacOs issue but with certain path length known issue in windows
Based on How to zip folder without full path, I had to update my script to first cd into the TARGET_BUILD_DIR before generating the zip. I also had to remove the -j flag so the local folder structure was retained on running unzip.
cd ${TARGET_BUILD_DIR}
XCTEST_FILE=./${TARGET_NAME}.xctest
XCTEST_ZIP=../../${TARGET_NAME}.xctest.zip
zip -r ${XCTEST_ZIP} ${XCTEST_FILE}

unzip multiple zip files from within one biz zip file using Git Bash command line

I am new to this forum and new to working with Git Bash command line windows application. I have a task at hand that require to keep code in Git Hub. So start using Gitbash to transfer files to GitHub. I am having a problem to automate unzipping the code that i get from my Dev team. They send me a biz zip file with multiple zip files inside as a package / collection of zip files in a big zip file. e.g. the big zip file will contain: WebCode.zip SQL.zip SSIS.zip Reports.zip Release notes.docx
My Challenge is that, how can I unzip file: BigZipFIle.zip and its contents all in one shot: under GitBash command line prompt:
unzip -o BigZipFIle.zip
gives me folders:
WebCode.zip
SQL.zip
SSIS.zip
Reports.zip
what I actually want to do is to have a script that would:
unzip BigZipFIle.zip in the same folder c:\bigZipFile\
unzip all additional zipped folders:
go into each folder, pickup the unzipped files
transfer to GitHub respective folder, I have similar folder structure in github
I would really appreciate if some can help me create a script.
Thank you, Nad

Wget Folder in Bash

I'm trying to use wget in bash to get a folder from my ftp host, but when I download the files it makes new folders for the folder that I'm downloading. For example, when I use this script to download my folder:
wget -r "ftp://$USER:$PASS#example.com/subdomains/cydia/httpdocs/theme/themes/$theme_root"
It creates a folder called "example.com" then within that one it makes "subdomains" and so on. I just want it to download the $theme_root folder that I'm downloading into the folder that I used cd to get into (/theme_builder/themes). Sorry if I'm not explaining this well but thanks in advance!
wget -nH --cut-dirs=4 -r url
I hope, than counted right... if not, change the 4 to another number.

Wget Not Downloading Every Folder

Hey, I have bash script running a wget command to get a directory:
wget -r -nH --cut-dirs=5 "ftp://$USER:$PASS#stumpyinc.com/subdomains/cydia/httpdocs/theme/themes/$theme_root"
And what it's supposed to do is download a folder structure that looks like this:
$theme_root/Library/Themes/$theme_name.theme/Icons
For some reason, it wont download any folder that's inside of the $theme_name.theme folder. There's also a UIImages folder in there that's not showing up, although files that are in that folder are being downloaded. Does anyone notice anything that I might have done wrong? Thanks in advance!
EDIT
if you add --level=inf it works perfectly!
Wget's default directory retrieval depth is 5 directories as per the wget manual. If the files you are trying to get are deeper than that from your starting position, it will not go down there. You can try giving a larger --level option or as your edit --level=inf.

Resources