How to ZIP a whole folder( including Subfolders and files) using 7zip in PowerShell - powershell

I am trying to ZIP a whole folder( including Subfolders and files) using 7zip in PowerShell
Below is the code:-
& "$env:C:\Program Files\7-Zip\7zFM.exe" -mx=9 a "C:\Users\Rajat.Choudhary\Desktop\rajat\*" "C:\Users\Rajat.Choudhary\Desktop\backup.zip"
Every time the 7 Zip application opened when I executed this code in VS code editor.
Please suggest the solution for this.

Related

Count files in a ZIP file over SFTP using PowerShell

I am connecting to SFTP via host, port, username and password using PowerShell. I want to count the number of files in a particular zip folder without having to download the zip folder on my local machine and count. Please share the piece of logic that would do this. I looked into this but it seems a bit tricky when it comes to do this in a zip folder.
That's not an easy task to do. There's no API in SFTP to do that completely remotely. There are basically two solutions:
Use SFTP to download only the ZIP central directory (basically the listing that is placed at the very end of the ZIP file). And decode the directory locally. For C#, this is covered in my answer to List files inside ZIP file located on SFTP server in C#. Though as mentioned there, there's a bug in SSH.NET that requires a workaround with implementing an interface. While that's probably doable in PowerShell too, I've never done that.
If you have an SSH shell access to the server, use remote zip command to list the contents of the file. Or build another API (like a web service).
Btw, note that there's nothing like ZIP "folder". ZIP is an archive file. It's only Windows that call ZIP files "folders".

Attribute "A" missing in the zipped file through powershell "Compress-Archive"

Compressed a file through powershell Compress-Archive feature.
On opening the archive in the 7-zip there is no 'A' in the attribute column, i believe 'A' stands for archive.
When file compressed through windows feature (send to -> Compressed (zipped) folder) "A" attribute is present(When opened archive in 7-zip).
How can I get the 'A' attribute when zipped through Compress-Archive?
Real problem:
I am trying to unzip the file through puppet.
unzip working on files zipped through windows feature
unzip not working on Compress-Archive feature (only through puppet, normal unzip command is working)
On opening both the zipped files (through Compress-Archive, windows feature) in 7-zip archive I observed that attribute 'A' is missing in the zipped (Compress-Archive) file.
Please help.
Tagged puppet as well, could be a known scenario.

How to include files and folders with 7zip powershell

Im trying to make my powershell script zip up a few files and folders. At the moment I can make my script either zip all files (with no folders included), or zip all files with folders included but to the wrong path.
An example would be if I have a folder named wordpress with files and a few subfolders. I need my zip file to be wordpress.zip, with all files and subfolders being in the root of that zip as opposed to \wordpress\files.*
Any help would be appreciated. Here is my code so far
function create-7zip([String] $aDirectory, [String] $aZipfile){
[string]$pathToZipExe = "C:\Program Files\7-zip\7z.exe";
[Array]$arguments = "a", "-tzip", "$aZipfile", "$aDirectory";
& $pathToZipExe $arguments;
}
create-7zip "$storageDir\wordpress\*.*" "$storageDir\wordpress.zip"
The above example will only zip files inside of my target folder, I need it to include the subfolders as well.
create-7zip "$storageDir\wordpress\*" "$storageDir\wordpress.zip"
will include files and subfolders.

How do i FTP upload directory in Powershell

I came across this post:
Upload files with FTP using PowerShell
But I'm looking how i can upload a directory with files in it to a FTP server.
Thanks in Advance
You should write a script that loop into directory and then upload files one by one. I don't remember that ftp command on windows can upload an entire directory.
You should find example here :
http://www.dostips.com/DtTipsFtpBatchScript.php

Using wildcards for filenames in powershell

I am having a lot of issues trying to automate downloading from an ftp site. I know the folder the file will be in, and I know that it will be a .zip file. However I do not know what the files will be named.
So I have code that works if I know the file name...for example:
$sourceuri = "ftp://myFtpSite/test/myZipFile.zip"
I would like to be able to use wildcards in this string so it will recongize any zip file. So I could write something like
$sourceuri = "ftp://myFtpSite/test/_.zip"
and it would download any zip file in that folder.
I know this question is ancient, but have you considered just using the console app ftp.exe? You can build a text file with commands (such as "mget *.zip" to retrieve all .zip files) and automate the process.
ftp -s:filename