How to upload all the files from local to host using Curl?

i have written a shell script to upload all files with different names in the specific path from local to host, but i have facing some issue and the files are not getting uploaded

#!/bin/sh
for file in /main/folder1/path/*
do
curl -u Pass:"Uname" -T $file
done

please help me to solve this.

i am getting the error as following

<html>
<head>
<title> 500 Internal Server Error </title>
</head>
<body>
<h1>
Internal Server Error
</h1>
</body>
</html>

currently i am having the script inside /main/folder_2, if i change /main/folder_1/path/* to ../folder_1/path/*, i got the output, the files are moved as expected. but i want to run the script with the complete path specified.

2

1 Answer

I would change you script like so:

#!/bin/sh
for file in /folder/path/*
do curl -u username:password -T ${file}
done

Note that the for-loop variable file is used with curl.

Better way is to upload using find + curl (as was answered on SO):

find /folder/path/ -name '*' -type f -exec curl -u USERNAME:PASSWORD -T {} \;

P.S. More info about

some issue is stopping the files getting uploaded

would be helpful.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like