Upload File with CURL into Website - batch-file

I try to Upload a File into a Website with cURL on Windows CMD. The html-code looks like this:
<form enctype="multipart/form-data" action="/Filebrowser?Path=/S71500/" method="POST" onsubmit="return checkUploadFile()">
<td><input id="filebrowser_upload_filename" type="file" name="filename" size="30" maxlength="80" style="background-color: transparent;"></td>
<td><input type="submit" value="Datei laden"></td>
</form>
The command i am using is:
curl -F "filename=#/Users/Me/FILE.so" http://localhost:8080
The fail-message is:
Warning: setting file FILE.so failed!
curl: (26) read function returned funny value
What am I doing wrong?

for me, it was a permissions thing. Curl wasn't able to read my file because it wasn't readable. try:
sudo chmod a+r /path/to/your/file
also, make sure to verify that you are logged in as either root or the owner of the file
ls -l /path/to/your/file
will give you info about permissions, ownership, and group for example:
-rw-r--r-- 1 me users 792139 Jul 2 11:23 file.txt
file.txt is readable by root, "me" and members of the group "users" - writable only by root, and not executable by anyone. it contains 792139 bytes

I had the exact same error, while trying to upload with curl:
Warning: setting file testimage.png’ failed!
It comes out to be because my curl command line contained spurious invisible characters from a copy/paste from browser. I copied the command line into a text editor like Sublime Text and then back into terminal: suddenly everything worked.
Probably some UTF8 / ASCII issue.

Instead of -F, we have to use --form-string. Then it will work.

You should place a PHP code in the root directory of your server as below
upload.php
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['filename']['name']);
if(move_uploaded_file($_FILES['filename']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['filename']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
keep in mind that you must use the argument a capital F (for Form). Lowercase f is for fail

Related

When executing a batch file from python, the output is only the first line

I'm using the 'qwinsta' cmd command to get the session ID of a remote computer and output it to a textfile, so I create a new batch file and write the command then I try running the batch file through python but it only returns the first line of the output. When I run the batch file by simply double-clicking it it works properly.
Using python 2.7:
def run_qwinsta(self, computerName):
qwinsta_check = open("q.bat", "w")
qwinsta_check.write('PsExec -u <username> -p <password> \\\\' + computerName + ' qwinsta' + ' > "q.txt" ')
qwinsta_check.close()
os.system("q.bat")
Expected results:
SESSIONNAME USERNAME ID STATE TYPE DEVICE
>services 0 Disc
console <username> 1 Active
rdp-tcp 65536 Listen
Actual results:
SESSIONNAME USERNAME ID STATE TYPE DEVICE
I would recommend you to avoid writing the batchfile, If you can. You can execute your batch command from os.system(). Also you can try using subprocess (documentation here) and then redirecting the stdout and stderr to file.
EDIT:
PsExec is a good choice, but If you want another way, you can also use ssh.
You can run PsExec from os.system() and then write the response to text file on the remote machine. The default PsExec working directory is System32 there you can find your text file.
Tested code:
import os
os.system('Psexec \\\\SERVER cmd.exe /c "tasklist > process_list.txt"')
I used tasklist, because I don't have qwinsta on my remote machine.
If you want to store the PsExec response on your machine you can use subprocess and then redirect the stdout to text file.
Tested code:
import subprocess
process_list = open("process_list.txt", "w")
subprocess.call(['Psexec', '\\\\SERVER', 'tasklist'], stdout=process_list)
process_list.close()
Actually I used Python 3.x, because I don't have Python 2.x, but it should work on both.
If this still didn't solve your problem, please provide more details to your question!

sfdx force:data:bulk:upsert request contains invalid data

Having some trouble using the bulk:upsert command to update Account objects via a csv file. Hopefully someone can help me with this. Below is what I'm doing:
My csv file name is account.csv and it contains the following data:
Id,Name
0012F00000QjhC7QAJ,LimTest 1
0012F00000QjhkSQAR,LimTest 2
Below is the command that I'm running:
sfdx force:data:bulk:upsert -s Account -f account.csv -i Id -u dev
Above command gets submitted sucessfully. But the job failed.
The Batch status is as of below:
When I view the request, it looks like below:
It works after I manually created an empty file and copied and pasted the data into this new file. The original file, account.csv, was created using this command:
sfdx force:data:soql:query -q "select Id, Name from Account" -r csv -u dev > account.csv
I guess the above command must have created the file in a different encoding that the bulk:upsert does not know how to handle.

SOLR POST files with no extension

I am using SOLR 5 and I want to scan documents that have no extensions. Unfortunately changing the file to have extensions is not an option in my case.
the command I am using is simply:
$bin/post -c mycore ../foldertobescaned -type application/pdf
the command works fine for documents that do have extension but I am getting:
Entering auto mode. File endings considered are xml,json,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log
If renaming the files is not an option, you can use the following script as a workaround until Solr improves its post method. It is a simple bash for loop that submits each file individually and works regardless of the file extension. Note that this script will be slower than using post on the whole folder, because each individual file transfer needs to be initialized.
Save the script below as postFolderToSolr.sh inside your Solr folder (so that Solrs bin/ folder is a subdirectory), make it executable with chmod +x postFolderToSolr.sh and then use it as follows: ./postFolderToSolr.sh mycore /home/user1/foldertobescaned/ application/pdf
Using no arguments or the wrong number of arguments prints a short usage message as help.
#!/bin/bash
set -o nounset
if [ "$#" -ne 3 ]
then
echo "Post contents of a folder to Solr."
echo
echo "Usage: postFolderToSolr.sh <colletionName> </path/to/folder> <MIME>"
echo
exit 1
fi
collection=$1
inputPath=${2%/} # remove suffix / if it exists
mime=$3
for element in $inputPath"/"*; do
bin/post -c $collection -type $mime $element
done

psftp - Script file is not running

I have a script as sftpScript.bat and trying to run it in psftp. here is what I am trying in psftp (I have tried through cmd and then entering psftp):
psftp>open L2_SERVSEND#ecdev1.idev.fedex.com 60022 -b sftpScript.bat
Using username "L2_SERVSEND"
Connected to hostSSH server: password
Using keyboard-interactive authentication.
Enter password for L2_SERVSEND
Password:
Remote working directory is /L2_SERVSEND
psftp>
(I provided the password for the user when it asked!)
here is what my script file contains -
cd ..
cd L2_SERVRCV\APPTYPE
put sample.txt
put sample.txt
put sample.txt
put sample.txt
put sample.txt
put sample.txt
put sample.txt
Basically, I am tring to go inside the receiver's folder and then transfer sample.txt file to receiver i.e. L2_SERVRCV
I tried using -P while giving the port no but getting error "Port no invalid"; not sure why - that is not the priority as of now.
What I am expecting is that the script file should run and the sample.txt file should be transferred. But its not happening really!
P.S. - My all the files (psftp.exe, sftpScript.bat and the sample.txt) are in the same folder i.e. desktop.

Facing a file permission error while running CakePHP in Ubuntu 10.4

I have installed CakePHP 2.0 framwork using steps below:
1. Start the terminal
2. sudo mkdir /var/www/cakephp
3.sudo cp -r ~/cakephp/* /var/www/cakephp
Change tmp folder permisssion
4. sudo chmod -R 777 cakephp/app/tmp
Enable mod-rewrite
5. sudo a2enmod rewrite
Open file /etc/apache2/sites-enabled/000-default and change AllowOverride None to AllowOverride All
6. sudo vim /etc/apache2/sites-enabled/000-default
Restart Apache
7. sudo /etc/init.d/apache2 restart
I opened my browser and typed address http://localhost/cakephp/ and I seaw this error message:
Warning: _cake_core_ cache was unable to write 'cake_dev_en-us' to File cache in /var/www
/cakephp/lib/Cake/Cache/Cache.php on line 310
Warning: _cake_core_ cache was unable to
write 'cake_dev_en-us' to File cache in /var/www/cakephp/lib/Cake/Cache/Cache.php on line 310
Warning: /var/www/cakephp/app/tmp/cache/persistent/ is not writable in /var/www/cakephp
/lib/Cake/Cache/Engine/FileEngine.php on line 320
Warning: /var/www/cakephp/app/tmp/cache
/models/ is not writable in /var/www/cakephp/lib/Cake/Cache/Engine/FileEngine.php on line 320
Warning: /var/www/cakephp/app/tmp/cache/ is not writable in /var/www/cakephp/lib/Cake
/Cache/Engine/FileEngine.php on line 320
The command sudo chmod -R 777 cakephp/app/tmp only made tmp writable, you should make cache and it's subdirectories writable as well, otherwise Cake can't write the cache files to the cache directory in tmp.
So, these directories should be writable:
cakephp/app/tmp/cache
cakephp/app/tmp/cache/persistent
cakephp/app/tmp/cache/models
Make sure the log directory is writable as well: cakephp/app/tmp/logs.
I've faced similar problems. Here are a couple of things that helped me:
If you don't want to use the "sledgehammer" approach of chmod 777 (you may want to avoid it on production, for instance), the CakePHP installation instructions provide details on how to use ACL instead:
For Cake 2: http://book.cakephp.org/2.0/en/installation.html#permissions
For Cake 3: http://book.cakephp.org/3.0/en/installation.html#permissions
Note that you'll probably need to use sudo for the setfacl commands given there.
However, in my experience (CakePHP 2), those commands aren't enough. These commands give your webserver user access to the cache etc, but anything you run from the command line (like the cake command) will probably be running as your user rather than the webserver user.
Therefore, you should run the setfacl commands linked to above a second time, replacing ${HTTPDUSER} with your user name. If you're not sure what your username is, type whoami to find it.
I have encountered a very similar problem with cachePhp 3.
Warning (512): /cache/persistent/ is not writable [CORE/src/Cache/Engine/FileEngine.php, line 439]
Warning (512): Cache engine Cake\Cache\Engine\FileEngine is not properly configured. [CORE/src/Cache/Cache.php, line 177]
Because I am new in CakePhp, I have debuged the file with problem - CORE/src/Cache/Engine/FileEngine.php.
Here is function like next:
protected function _active()
{
$dir = new SplFileInfo($this->_config['path']);
$path = $dir->getPathname();
$success = true;
if (!is_dir($path)) {
//#codingStandardsIgnoreStart
$success = #mkdir($path, 0775, true);
//#codingStandardsIgnoreEnd
}
$isWritableDir = ($dir->isDir() && $dir->isWritable());
if (!$success || ($this->_init && !$isWritableDir)) {
$this->_init = false;
trigger_error(sprintf(
'%s is not writable',
$this->_config['path']
), E_USER_WARNING);
}
return $success;
}
It checks if cache directory is writable and get data about path form $this->_config['path'] variable. This variable is initialized by default from .env file (if you use it), and it has lines like next:
export CACHE_DEFAULT_URL="File://tmp/cache/?prefix=${APP_NAME}_default&duration=${CACHE_DURATION}"
export CACHE_CAKECORE_URL="File://tmp/cache/persistent?prefix=${APP_NAME}_cake_core&serialize=true&duration=${CACHE_DURATION}"
export CACHE_CAKEMODEL_URL="File://tmp/cache/models?prefix=${APP_NAME}_cake_model&serialize=true&duration=${CACHE_DURATION}"
I have changed all File: to Null:, like next:
export CACHE_DEFAULT_URL="Null://tmp/cache/?prefix=${APP_NAME}_default&duration=${CACHE_DURATION}"
export CACHE_CAKECORE_URL="Null://tmp/cache/persistent?prefix=${APP_NAME}_cake_core&serialize=true&duration=${CACHE_DURATION}"
export CACHE_CAKEMODEL_URL="Null://tmp/cache/models?prefix=${APP_NAME}_cake_model&serialize=true&duration=${CACHE_DURATION}"
export CACHE_DRV_DEFLT = "Null"
export CACHE_DRV_MODEL = "Null"
export CACHE_DRV_CORE = "Null"
And it helps, my problem was fixed. Probably it will be helpfull for someone. Enjoy!
Using chmod -R 777 /var/www/cakephp/app/tmp/ i.e. making folder execuatble will solve this issue.
I even faced similar issue while testing cron i.e. shell which exists in app/Console/Command/ folder. When we execute a cron multiple time, tmp/ folder permission is overwritten and permission error will come in picture at this point which can be avoided by making tmp/ folder executable recursively.
As a temporary fix, if you want to use the provided .env file and permissions did not solve your issue modify the .env file to use absolute path that points to your app directory
export CACHE_FOLDER="/var/www/absolute_path_to_my_cakephp_app/"
export CACHE_DURATION="+2 minutes"
export CACHE_DEFAULT_URL="file://${CACHE_FOLDER}tmp/cache/?prefix=${APP_NAME}_default&duration=${CACHE_DURATION}"
export CACHE_CAKECORE_URL="file://${CACHE_FOLDER}tmp/cache/persistent?prefix=${APP_NAME}_cake_core&serialize=true&duration=${CACHE_DURATION}"
export CACHE_CAKEMODEL_URL="file://${CACHE_FOLDER}tmp/cache/models?prefix=${APP_NAME}_cake_model&serialize=true&duration=${CACHE_DURATION}"
“chmod -R 777 tmp/cache” if tmp folder is not exists then create tmp file using mkdir tmp and mkdir tmp/cache
chmod -R 777 logs
chmod -R 777 tmp/sessions
chmod -R 777 tmp/tests
chcon -R -t httpd_sys_content_rw_t 'tmp'
chcon -R -t httpd_sys_content_rw_t 'logs'

Resources