I am trying to find a way to upload batch of files from one server to another by cron few times a day and wput seems like best and easiest option to use.
It works so far fine, but problem is that wput always recreating directory tree on destination. So here is command i use.
wput -u /var/www/clients/client1/web/parser/*.json ftp://username:password@remoteserver/web/So this is supposed to upload all the files inside directory /parser/ and files that have .json extension.
This works very nice, except:
When it upload the files to remote server it uploads whole directory tree and instead of having a list of files inside /web/ folder on remote server the files are uploaded with all directories from source server
Instead having this:
/web/file1.json
/web/file2.json
/web/file3.json
/web/file4.jsonI have this
/web/var/www/clients/client1/web/parser/file1.json
/web/var/www/clients/client1/web/parser/file2.json
/web/var/www/clients/client1/web/parser/file3.json
/web/var/www/clients/client1/web/parser/file4.jsonHow can i prevent wput to upload whole directory tree on remoteserver?
21 Answer
The problem is that wput is always recreating the directory tree on the destination
You need to use the −−basename=path option:
This option causes
Wputto snip path from all input−files when they are connected to the URL.wput /usr/share/doc.tgz ftp://host/would createftp://host//usr/share/doc.tgz, whereas specifying/usr/share/as basename will result inftp://host/doc.tgzbeing created.
Source wput
Try the following command:
wput --basename=/var/www/clients/client1/web/parser -u /var/www/clients/client1/web/parser/*.json ftp://username:password@remoteserver/web/ 1