LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Wput script (https://www.linuxquestions.org/questions/linux-newbie-8/wput-script-931094/)

ceantuco 02-24-2012 01:23 PM

Wput script
 
Hi,

I created a script to upload a file to my ftp server once week. The problem is that the file name changes every day. is there a way I could setup this script to copy *.123 instead of specifying a file name?
script:
echo off
echo Backing up your data offsite, please wait...
cd \
cd folder
cd backup
wput -v *.123 ftp://ftpuser:password@ftpserver/ftpfolder/

I tried this script but it did not find the file above *.123.

Thank you!

ricstirato 02-24-2012 03:09 PM

Why not replace the last line with the following:

for FILE in *.123; do
wput -v $FILE ftp://ftpuserassword@ftpserver/ftpfolder/
done

corp769 02-24-2012 03:13 PM

Before I go fully answering this, what type of script is this? I ask because I see the "echo off" above, and it reminds me of windows.... Also, what shell are you using? Normally in linux, this would work. A quick solution off the top of my head, in linux, would be to list all files with that extension, and pipe to a new file, then use the -i argument with wput, a such:
Code:

cd /folder/backup
ls *.123 > file1
wput -i file1 ftp://user:password@server/folder/


ceantuco 02-24-2012 09:30 PM

ricstirato, I will try that. Thanks for your response.
corp769: Yes, it is a W$ndows machine. It is a DOS batch file.
Thanks

corp769 02-25-2012 02:43 AM

Well then that explains it. Why would you post a windows type question in a linux forum? Reporting this thread to be moved... Sorry to come off as a dick, but seriously, these are linux forums...... Hope you understand! And by the way.... I don't use windows at all, let-alone script batch files anymore. Sorry I can't help you, but I can not emulate what you are trying to do, since I don't have windows installed on any of my computers.

Cheers,

Josh

ceantuco 02-27-2012 02:46 PM

Josh,

The reason why I posted it is because I am using 'wput' which I believe is an Open Source program that comes for Linux and W$ndows. Also, the FTP where the file is being uploaded to is a Ubuntu LTS server running vsftpd server. If I go to a W$ndows forum, I am sure they will direct me to a 'paid FTP program' to be able to accomplish what I want to do. I wish I could get rid of W$ndows but there are many applications that need to be run under W$ndows.

chrism01 02-27-2012 05:31 PM

In that case, the easiest way to take advantage of solns above that use Linux shell is to install Cygwin on your MS system.
This gives you a *nix style interface (in addition to whatever is there already), so that you can use most shell cmds and other *nix tools.

ceantuco 03-12-2012 08:28 AM

Thank you Chrism! I will try that. I appreciate your help. Cheers!

lithos 03-12-2012 09:52 AM

Hi ceantuco

there is a way if using command line FTP client - LFTP (install Cygwin and when installing packages check LFTP)

and then you can use command "mput":
Code:

mput
Usage: mput [OPTS] <files>
Upload files with wildcard expansion
 -c  continue, reput
 -d  create directories the same as in file names and put the
    files into them instead of current directory
 -E  delete local files after successful transfer (dangerous)
 -a  use ascii mode (binary is the default)
 -O <base> specifies base directory or URL where files should be placed

All in one line would be:
Code:

lftp -c "open $HOST && user $USER $PASSWD && cd FOLDER_NAME_FOR_STORING/backups/ && mput $FILE"
where:
- $HOST is your ftp address
- $USER $PASSWD - self explanatory
- $FILE - filename / names pattern

like:
lftp -c "open mysiteftp.net && user ftpuser ftppassword && cd /home/ftpuser/backups && mput *.123"


All times are GMT -5. The time now is 07:57 AM.