how to use curl --ftp-create-dirs? - bash

Background
I have been searching the Internet trying to find an example of --ftp-create-dirs.
Overall my goal is to use "--ftp-create-dirs" to automatically create the necessary folders if they are not present when I upload my file.
Problem
The problem is I don't know the exact syntax for properly using --ftp-create-dirs, can someone help me with this?
My current curl:
curl -k -T 000-0000-0000-000.png -u [username]:[pass] --ftp-create-dirs /test --ftp-ssl ftp:[ftp server]
In the example above, I am trying to upload the .png image and create /test on the ftp server if it does not exist.

To add a new directory via FTP:
curl ftp://username:password#10.10.10.10/homes/back/newdir/ --ftp-create-dirs

Just putting this in here for future reference (and because I keep making the same mistake that I just saw in your code): it is important to end your folder name with a / (slash). Otherwise, curl will create a file, not a folder. Here is the command I used:
curl -T path/to/local_file.txt ftp://1.2.3.4/my_new_folder/ --ftp-create-dirs -u username:password
This will move local_file.txt to my_new_folder on the FTP server. The folder will be created if it doesn't exist, otherwise, the command will simply be ignored.
If there are any issues with creating the folder, curl will return error number 9 (see https://curl.haxx.se/libcurl/c/libcurl-errors.html). This can happen if a file with the same name as the new folder already exists in the given directory:
curl: (9) Failed to MKD dir: 451

You don't need to use the /test after the --ftp-create-dirs. Its just a parameter similar to your -k(doesn't take any value) at the command.

Related

How to upload .jtl file to blazemeter sense

I created a Jenkins job where it run some JMeter scripts and return .jtl files. Now, I want to upload this files to Blazemeter Sense to see the performance test, downloads pdf reports, etc.
I've searched a lot of information, where I find that to upload some file, I can use this command thats running from Windows CMD:
curl -v https://sense.blazemeter.com/api/files -H "Authorization: Token 'cat ~/.loadosophia.token'" -F "projectKey=Project_name" -F "jtl_file=#jtl.gz"
REFERENCE: https://sense.blazemeter.com/wiki/help:uploads/
The only values that I change are
cat ~/.loadosophia.token, where I replaced for my Upload Token (finded in Blazemeter Sense -> Options -> Settings -> Your Upload Token)
projectKey where I replaced by my project name (test_taurus)
jtl_file where I replaced by the file directory generated by Jmeter test (.jtl)
The final command is:
curl -v https://sense.blazemeter.com/api/files -H "Authorization: Token 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXYLaa'" -F "projectKey=test_taurus" -F "jtl_file=/path/of/file/file.jtl"
I missed some? What is my wrong? Existe another posibility to make it?
Thanks everyone
U P D A T E:
I did what Dmitri T said. Thats works. But when I run the command, the output is the following:
What could be the issue?
You need to remove quotation marks around the token
You need to add an "at" symbol before the .jtl file path
Fixed command would be something like:
curl -v https://sense.blazemeter.com/api/files -H "Authorization: Token XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXYLaa" -F "projectKey=test_taurus" -F "jtl_file=#/path/of/file/file.jtl"
More information: Upload files with CURL
You might find BM.Sense Uploader plugin more convenient to use, the plugin can be installed using JMeter Plugins Manager:

How to append a file with the existing one using CURL?

I've searched all over the web but couldn't find anything useful for this. Using CURL, I want to append content to a file which is already existing and named as test.pls. Can anyone please tell me how can I do it using curl. The commands I've tried are
curl http://192.99.8.170:8098/stream --output test.pls
curl -K --output test.pls http://192.99.8.170:8098/stream
curl -a --output test.pls http://192.99.8.170:8098/stream
But all of above starts creating files from scratch.They don't keep the initial content of file Can anyone please help me!
Use the shell's appending output redirection (>>) rather than curl's --output option.
curl http://192.99.8.170:8098/stream >> test.pls
A much easier and cleaner way is as follows:
curl -sS https://address.to.file.txt >> file-name.txt

File contains path instead of text

I'm trying to transfer a file with curl and it's getting created on the remote server, however the file contents are the path to the file instead of the actual contents of the file.
curl -x "poxy" --user user:pass --verbose -X PUT --data-binary "#D:\test.txt" "url/test.txt"
On the server, I see test.txt get created but the contents are:
D:\test.txt
On the local machine, the contents of the file are:
hello world
Note this is on cURL for windows if it matters.

Wget mirror site via ftp - timestamps issue

A site I'm working on requires a large amount of files to be downloaded from an external system via FTP, daily. This is not of my design, it is the only solution offered up by the external provider (I cannot use SSH/SFTP/SCP).
I've solved this by using wget, run inside a cron task:
wget -m -v -o log.txt --no-parent -nH -P /exampledirectory/ --user username --password password ftp://www.example.com/"
Unfortunately, wget does not seem to see the timestamp differences, so when a file is modified, it still returns:
Remote file no newer than local file
`/xxx/data/data.file'
-- not retrieving.
When I manually connect via FTP, I can see differences in the timestamps, so it should be getting the updated file. I'm not able to access or control the target server via any other means.
Is there anything I can do to get around this? Can I force wget to mirror while ignoring timestamps? (I understand this defeats the point of mirroring)...

curl issue while uploading files to ftp

I have an issue while I need from script to upload all files which stored in some directory. Every time I get this issue:
curl: (9) Server denied you to change to the given directory
#!/bin/sh
for file in /export/test/*
do
curl -T ${file} ftp://192.168.10.10/${file} --user tester:psswd
done
I checked vsftpd config and I have permissions to write/read and when I do it manually It runs.
for example when I run this command, everything is OK.
curl -T /export/test/testing.txt ftp://192.168.10.10/export/status/testing.txt --user tester:psswd
Have someone else also this problem?
I don't have any idea how to solve it, I tried everything.
By the way: My ftp root folder is /var/www/stats and I need to rewrite files in subfolders which is named: /var/www/stats/export/test.
FIXED
my bad: error is in that file variable putting full path to server and I put one more slash there.
so final conclusion is this:
#!/bin/sh
for file in /export/test/*
do
curl -T ${file} ftp://192.168.10.10${file} --user tester:psswd
done
It works. Done.

Resources