Help with FTP Variable Transfer


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with FTP Variable Transfer
# 1  
Old 08-20-2010
Question Help with FTP Variable Transfer

Hey all,
I'm trying to upload a file to my ftp server through an automated batch program. I will be uploading a file that's name changes according to you IP Address, so I am using the variable %ip% to represent the file's name. The problem occurs when it transfers over to the ftp portion of the batch program, as the file isn't found because the ftp portion can't use the batch portion's variables. I was wondering if it was possible to transfer the variables over to the ftp portion, and if so, how would it be done.

Here is the code I am using:

Code:
set ip=%1
echo %1 > %1.txt
%windir%\system32\ftp.exe -v -i -s:"%~f0"
goto done
open ftp.server.to.use
username
password
cd folder1
cd folder2
put %ip%.txt
bye
:done

From another program I run it using:

Code:
start ftpupload.bat yourip


Last edited by piking; 08-21-2010 at 12:27 PM..
# 2  
Old 08-21-2010
I'm not at all familiar with windows batch files, so this might not be possible. However, as nobody has posted anything, I thought it might be worth considering.

In the past I have generated a file with all of the necessary ftp commands and redirected that file into ftp from the command line. In psuedo code, it looks something like this:

Code:
echo "cd $target_directory" >ftp_cmds
echo "put $file_var1" >>ftp_cmds
echo "put $file_var2" >>ftp_cmds
echo "quit" >>ftp_cmds

ftp targethost <ftp_cmds

I'm assuming that the batch processor under windows can expand a variable name on the echo, and thus the resulting file will contain the desired filename and not the unexpanded variable name.

Don't know if the windows based ftp supports a .netrc or like file in which passwords and usernames can be securely kept. If it does, I'd suggest looking into using that; it's not a good idea to have usernames/passwords floating round in your scripts.
This User Gave Thanks to agama For This Post:
# 3  
Old 08-21-2010
Thanks, I'll try it. As for the passwords and usernames, I am going to convert it to an executable when I am finished.

EDIT:
Thanks it worked, but I messed something up and it won't load it know. Oh well, I'll keep messing with it.

EDIT 2:
Thanks it is now fixed! Smilie

Last edited by piking; 08-21-2010 at 01:37 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to see the status of all the ftp put & get files logs and curent ftp transfer status ?

How to see the status of all the ftp put & get files logs and curent ftp transfer status if any active ftp running in the background ? (2 Replies)
Discussion started by: i4ismail
2 Replies

2. Shell Programming and Scripting

Transfer multiple different files in FTP

Hi All, i am doing ftp how can i transfer multiple different files example- 03-21-13 06:33AM 46800 CATT_HOURS.pgp 03-21-13 06:33AM 266392 CATT_TAX.txt 03-21-13 06:33AM 91448 CATT_STATUS.txt 03-21-13 06:33AM 468 ... (3 Replies)
Discussion started by: krupasindhu18
3 Replies

3. Shell Programming and Scripting

ftp transfer in a for loop

Frdz, i have scenorio like i have to open ftp connection in a for loop and connect to the other server and upload the file again and again till the for loop ends but i am getting problem when i use the following code. for i in `ls ${SOURCE_DIR}/` do FOLDER_NAME=`basename $i` for j in `ls... (4 Replies)
Discussion started by: KiranKumarKarre
4 Replies

4. Shell Programming and Scripting

FTP (File Transfer)

I am going to transfer file from UNIX directory to remote windows location and i wrote the script but i am getting the error as 'FTP: not found' or i am getting this error 'The file path is not found'. Please help me to resolve this problem as early as possible.(urgent). my script is, ... (6 Replies)
Discussion started by: praka
6 Replies

5. Shell Programming and Scripting

File Transfer through FTP

Hi Guys, I wanted to transfer files from FTP machine to Linux Machine. In this, I need to create a batch file that will connect to the Linux Machine and Transfer the files specified as the parameter to the files. Ex : transferfiles Product Time Geography Here transferfiles shld contain... (4 Replies)
Discussion started by: Swapna173
4 Replies

6. Shell Programming and Scripting

file transfer using Ftp

Hi All, I am very new to shell scripting,I have some doubts how we can do a file transfer using ftp I wanted to transfer files using non_secure ftp and secure ftp(sftp) mode, for secure ftp i am using following code verbose="verbose" ftp="/usr/bin/ftp" user="ABC" pass="123"... (1 Reply)
Discussion started by: sudhi
1 Replies

7. UNIX for Dummies Questions & Answers

ftp transfer permission denied

I am using a Cobalt Raq4 with Apache web server. I am trying to set the intermediate SSL certificate. I have edited httpd.conf and have created the intermediate SSL certificate text file. However when I try to upload the text file via ftp I get a "Permission denied" message. I am the server... (1 Reply)
Discussion started by: dennisheazle
1 Replies

8. Shell Programming and Scripting

FTP Transfer error

Hi ! I created a similar script as shown below to automate an FTP transfer and encountered errors. Appreciate any advice to resolve this issue. The script: #!/usr/bin/ksh ftp 'IP ADD' << cmd user 'user' 'pass' lcd /home/data get 'FileA' FileB quit cmd Connected to 'IP_ADD'.... (3 Replies)
Discussion started by: cosec
3 Replies

9. Solaris

ftp transfer

Hi ....I'm trying to ftp 2 pkgs SUNWqlc & SUNWqlcx since they were accidentally deleted from my servers. For one reaseon or the other my server is not loading the cdrom, so I mounted the cdrom on a differernt server & ftp's to it. I tried to get this pkg using the bin & I get an error message... (3 Replies)
Discussion started by: Remi
3 Replies

10. Shell Programming and Scripting

FTP Transfer Success

Hi I'm using Shell script which will ftp (download) a file from a host. I need to check whether the file has been transfered completley or not. Can anyone tell me how to do that? Thanks Ben (1 Reply)
Discussion started by: abrd600
1 Replies
Login or Register to Ask a Question