Zip or unzip a file with different file name encoding? [closed] - encoding

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I have files with name out-of-ASCII on a Linux server to zip. Unfortunately, UTF8-encoded files always have file name corrupted on extracting on Windows.
Is there a way to zip files with name encoded in a specific charset different to the local system charset? Or is there a tool that can extract UTF8-encoded files with correct name on Windows?
(If the solution is a script, PHP or Python are preferred.)

Use 7z or 7zip.
Compress your files on Linux and decompress on Windows both by 7-zip.

For python2 (filenames is russian) pls use cp866
with zipfile.ZipFile(file_handle, mode='w') as zip_file:
for file_ in self._files.all():
path = file_.file.path
filename = u'Название файла.txt'
try:
filename = filename_utf.encode('cp866')
except:
ext = str(path.split('.')[-1])
filename = '%s.%s' % (uuid4().hex, ext)
zip_file.write(path, filename)
For python 3
file_handle = BytesIO()
with zipfile.ZipFile(file_handle, mode='w') as zip_file:
for file_obj in files:
zip_file.write(filename=file_obj.full_path, arcname=file_obj.file_name)

Related

Ubuntu mailx attach file without the whole path as the filename [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 11 months ago.
Improve this question
I use the below command to send emails in an Ubuntu server. This seems to attach the testreport.csv file with its full path as the filename.
echo "This email is a test email" | mailx -s 'Test subject' testemail#gmail.com -A "/home/dxduser/reports/testreport.csv"
How can I stop this from happening? Is it possible to attach the file with its actual name? In this case "testreport.csv"?
I use mailx (GNU Mailutils) 3.7 version on Ubuntu 20.04
EDIT: Could someone please explain why I got downvoted for this question?
There are multiple different mailx implementations around, so what exactly works will depend on the version you have installed.
However, as a quick and dirty workaround, you can temporarily cd into that directory (provided you have execute access to it):
( cd /home/dxduser/reports
echo "This email is a test email" |
mailx -s 'Test subject' testemail#gmail.com -A testreport.csv
)
The parentheses run the command in a subshell so that the effect of the cd will only affect that subshell, and the rest of your program can proceed as before.
I would regard it as a bug if your mailx implementation puts in a Content-Disposition: with the full path of the file in the filename.
An alternative approach would be to use a different client. If you can't install e.g. mutt, creating a simple shell script wrapper to build the MIME structure around a base64 or quoted-printable encoding of your CSV file is not particularly hard, but you have to know what you are doing. In very brief,
( cat <<\:
Subject: test email
Content-type: text/csv
Content-disposition: attachment; filename="testreport.csv"
From: me <myself#example.org>
To: you <recipient#example.net>
Content-transfer-encoding: base64
:
base64 </home/dxduser/reports/testreport.csv
) | /usr/lib/sendmail -oi -t
where obviously you have to have base64 and sendmail installed, and probably tweak the path to sendmail (or just omit it if it's in your PATH).

.tar vs .tgz...what is the difference? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
So I was just archiving an assignment for email submission, and was asked by the instructor to do so using the tar command and create a .tgz file, which I did with the following command line script:
tar -cvf filename.tgz {main.cpp other filenames here}
No problems on the archive or anything, but when I went to email the file, gmail prevented me saying that my file contained an executable (I'm assuming main.cpp?), and that this was not allowed for security reasons.
So, I ran the same script, but this time created a .tar file instead, like so:
tar -cvf filename.tar {main.cpp filenames here}
Again, archives just fine, but now gmail is fine with me emailing the archive. So what is the difference? I've only really used tar for this purpose, so I'm not really familiar with what the different extensions are utilized for. Obviously, I've figured out a way to get the functionality I need, but like all tinkerers, I'm curious.
What say you?
Absolutely no difference. A filename is just a filename. Usually, when you use the tgz form, it's to indicate that you've gzipped the tar file (either as a second step or using the z flag):
tar zcvf filename.tgz {filenames}
or
tar cvf filename {filenames}
gzip -S .tgz filename
.tar, on the other hand, normally means "this is an uncompressed tar file":
tar cvf filename.tar {filenames}
Most modern tar implementations also support the j flag to use bzip2 compression, so you might also use:
tar jcvf filename.tar.bz2 {filenames}

Download file directly to FTP server [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I want to download a big file from a normal http-link to an ftp-server (under ubuntu) without storing the file locally (as my local storage is too small).
Do you have any ideas how to do this with wget or a small perl-script? (I don't have sudo-rights on the local machine).
Here's my take, combining wget and Net::FTP on the commandline.
wget -O - http://website.com/hugefile.zip | perl -MNet::FTP -e 'my $ftp = Net::FTP->new("ftp.example.com"); $ftp->login("user", "pass"); $ftp->put(\*STDIN, "hugefile.zip");'
Of course, you can put it in a file (ftpupload.pl) as well and run it.
#!/usr/bin/perl
use strict;
use warnings;
use Net::FTP;
my $ftp = Net::FTP->new("ftp.example.com"); # connect to FTP server
$ftp->login("user", "pass"); # login with your credentials
# Because of the pipe we get the file content on STDIN
# Net::FTP's put is able to handle a pipe as well as a filehandle
$ftp->put(\*STDIN, "hugefile.zip");
Run it like this:
wget -O - http://website.com/hugefile.zip | perl ftpupload.pl
There's - of course - a CPAN module which makes life easy for FTP:
http://search.cpan.org/search?mode=module&query=Net%3A%3AFTP
And WWW::Mechanize looks up files, follows links, etc.
With these modules I think you can solve your problem.
You can try to use wput. It is not very known tool, but i think you can use it.
Use wget's output-document option
wget -O /dev/null http://foo.com/file.uuu
From wget's manual page:
"-O file
--output-document=file
The documents will not be written to the appropriate files, but all will be
concatenated together and written to file. If - is used as file, documents will be
printed to standard output, disabling link conversion. (Use ./- to print to a file
literally named -.)
Use of -O is not intended to mean simply "use the name file instead of the
one in the URL;" rather, it is analogous to shell redirection: wget -O file http://foo is
intended to work like wget -O - http://foo > file; file will be truncated immediately,
and all downloaded content will be written there."
However, I can't see what could be the purpose of that

How can you search only filenames by find? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
This question is based on the answer.
I run at home
find -- ./ Desktop
I understand the command as
find without parameters
at the current directory that is home (= /Users/masi/)
find the folder name Desktop at the current directory
How do you read the command?
The answer to your question in the title is
$ find . -type f
Now, keep in mind that
$ find -- ./ Desktop
will return the files in Desktop twice.
In your example, "--" says to stop looking for further options. Everything else after that is a path, so it finds anything else matching that. And since "./" means "the current directory" it matches everything under the current directory (the Desktop will cause that directory, as well as anything inside it, to be reported twice.)
You probably want something like:
find ./Desktop -type f
Which will find any files inside the ./Desktop directory, that is a file (not directories, symbolic links, etc...)
I know that manpages can be quite technical sometimes, but "man find" will give you a wealth of other options that might help, as well as a few examples that may help with common problems.
I think what you want is:
find ./ -name Desktop
Well, you can pass multiple directories to search to find:
$ find --help
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
[...]
Note the "[path...]" indicating you can specify multiple paths.
So your example will find all files and directories under ./ (current dir) and under Desktop.

How to use afconvert to convert from .caf to .mp3 format? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am using the afconvert command line utility to convert an audio file from .caf to .mp3 format. I have used afconvert:
afconvert -f 'MPG3 ' -d '.mp3' -v input.caf output.mp3
But this gives me the following error:
Input file: input.caf, 19008 frames
Error: ExtAudioFileSetProperty ('cfmt') failed ('fmt?')
I have also tried the following:
afconvert -f 'MPG3 ' -d LEI32#44100 -v input.caf output.mp3
This also gives me the error:
Input file: min.caf, 19008 frames
Error: ExtAudioFileCreateWithURL failed ('fmt?')
I couldn't figure out why is this giving error.
Can anybody guide me in solving this problem?
Thanks in an advance.
you should check this,
afconvert -f mp4f -d aac -b 128000 input.caf output2.mp4
This way you will convert your CAF file to the MPEG-4 format.
Read: Apple does not ship any form of MP3 encoder with Mac OS X aside from the one built into iTunes.
source: http://lists.apple.com/archives/coreaudio-api/2005/Jul/msg00182.html
you should use 3rd party encoders if you need to encode mp3
Mp3 Encoder examples: lame encoder or ffmpeg :) good luck.
You can use the LAME encoder (On Mac, run brew install lame to install it).
First, you'll have to convert caf to wav (I had no chance to check if LAME supports caf as input, but it supports wav for sure).
Then run
lame --alt-preset cbr 128 sample.wav
This will create mp3 file with 128 kbps constant bitrate.
LAME has lot of settings, you can choose mp3 parameters as you wish.
try this:
afconvert -f mp4f -d aac -v input.caf output.mp3
I know it's not exactly mp3, but I couldn't get around that same error you are getting, so I tried mp4f and it worked.