|
Answer» hey all,
I'm starting my own website and I have files that are generated and stored by the site. These files are contained within numbered folders. Starting at 1 and going on forever....(i hope!)
I like to write a ftp script that when run will, connect to my site, navigate to the folder containing all the numbered folders, determain the highest number (ie, the latest folder to be created) and copy all the file within it to my machine.
Now, I never written an FTP script so I'm after some help.
This what I have so far;
batch file Code: [Select]FTP -s:ftpscript.txt
ftpscript.txt Code: [Select]USER MyUserId MyPassword cd Data
- I'm unsure how to find the highest numbered folder here
cd %to higest numbered folder%
mget *.*
- I'm unsure where the defulat download loaction would be.
I should mention that this will be started by Outlook VBA when a mail comes in, so needs to be completly automated, with no intervention by my-self.
Any help would be greatly appreciated.
Thanking you all
update;
I've decied that it would be much easier to not have to find the lastest folder on my site. I'll just keep one folder, download the data and then remove it.
so far I've got
ftp.bat Code: [Select]@echo off ftp -s:ftpscript.txt ftp.myhost.com exit
ftpscript.txt Code: [Select]cd data mget *.* bye
but if I run the batch file, it hangs. I've removed the @echo to de-bug but it just seems to run, "ftp -s:ftpscript.txt ftp.myhost.com" over and over again.
any ideas why??I am not sure what you are trying to do. Can you post the code you are using now and tell us what it is doing and what you want it to be doing?
sure,
At the moment all I'm trying to do is connect to a FTP site via batch. I'm trying to start the session from a batch file. (I want to add a script with commands in later, but felt it would be better to get the first step done right.)
ftp.bat Code: [Select]@echo off ftp ftp.myhost.com exit
If I run this batch file I get a prompt open with a blank winodw and it hangs. If I remove the "@echo off" I can see that it is running the command over and over again very quickly and causes my machine to become very sluggish.
I hope I've given enough info, please ask if not.
(OS = XP Pro and the FTP site is on the internet, not loacl. Incase you where wondering...) Here is a great place to start...
http://www.nsftools.com/tips/MSFTP.htm
The way I do this is to write a batch file that uses a text file for the user name and password. It ALSO has the commands to move files.
Here is a batch file:
ftp -n -s:E:\Folder\dataxfer.txt IP_Or domain name PAUSE
Than create a txt file called dataxfer.txt and put it in E:\folder It should have your commands in it like this.
user username password put E:\your_folder\file_name some_other_cool_commands bye
In my case I want to see the dos window do its stuff. If you don't want to see it run just get rid of the pause in your batch file. You will see a black box pop up and than close.
You can use your scheduler to run this for you if you need it.
Quote from: Spoiler on July 16, 2008, 08:49:13 AM The way I do this is to write a batch file that uses a text file for the user name and password. It also has the commands to move files.
Here is a batch file:
ftp -n -s:E:\Folder\dataxfer.txt IP_Or domain name PAUSE
Than create a txt file called dataxfer.txt and put it in E:\folder It should have your commands in it like this.
user username password put E:\your_folder\file_name some_other_cool_commands bye
In my case I want to see the dos window do its stuff. If you don't want to see it run just get rid of the pause in your batch file. You will see a black box pop up and than close.
You can use your scheduler to run this for you if you need it.
ok, I've copied you ftp line and sub'ed in my bits. I've edited my script.txt to change driectory and then log out. Sadly I'm still getting the same results.
Can you test something for me???
what happens when you a batch file with just "ftp ftp.myhost.com" in it???
Cheersarh,
turns out I had called my batch file "ftp.bat" and then when it ran the first line was "ftp ......" and so it was calling itself and got stuck in a loop!!!
Slap's hand to forehead!!!!!
Cheers for all the input guys!!!
Ok...try this....
Make a file and call it test_ftp.bat in it put this....
ftp -n -s:E:\Folder\dataxfer.txt ftp.myhost.com PAUSE
Now make another file and call it dataxfer.txt and put it in E:\folder Put this in it.
user your_username your_password put E:\folder\test_file.txt bye
Now open NOTEPAD and make a file called test_file.txt and save it to E:\folder
now edit the dataxfer.txt file to add your username and password. Also you will need to edit the ftp.bat file to replace the ftp.myhost.com to your ftp site.
One other thing....when you login to the ftp site do they make you change directories to your folder?
If they do than your dataxfer.txt should look like this....
user your_username your_password cd your_folder put E:\folder\test_file.txt bye
If you have done everything right this will copy the file called test_file.txt to your FTP site.
cheers Spoiler
I just renamed my batch file to something different and all's good.
Cheers again
good deal...glad things worked out for you.
have a good one!
I spoke to soon.
Although the batch file now connects to the ftp site sadly I'm getting "501 Syntax error in IP address" and "425 No data connection" error's while trying to download files.
I've LOOKED the error's up on google and it has pointed to a firewall issue, so I turned my windows firewall off, and allowed port 21 through my router's firewall (NAT to my laptop)
This hasn't helped, but strangely, If I open a command prompt and manually enter the commands as they are listed in my ftpscript.ftp file, its work without any issue.
Below is the log file generated by my batch file.
Code: [Select]Connected to ftp.myhost.com.
220---------- Welcome ---------- 220-You are user number 5 of 50 allowed. 220-Local time is now 16:54. Server port: 21. 220 You will be disconnected after 15 minutes of inactivity. User (ftp.myhost.com:(none)): 331 User me OK. Password required
230-User me has group access to: me 230 OK. Current restricted directory is / ftp> ASCII 200 TYPE is now ASCII ftp> Interactive mode Off .
ftp> prompt n cd Data/customer 250 OK. Current directory is /Data/customer ftp> get lname.txt 501 Syntax error in IP address
425 No data connection ftp> bye 221-Goodbye. You uploaded 0 and downloaded 0 kbytes. 221 Logout.
Any help greatly appreciated
|