James
asked on
FTP Script to upload a file
Hi Experts Exchange,
I need to create a FTP Script that will upload a file from a clients site to our FTP Server. This needs to be automated to run Monday - Friday at 9am.
Thank you,
JBond2010
I need to create a FTP Script that will upload a file from a clients site to our FTP Server. This needs to be automated to run Monday - Friday at 9am.
Thank you,
JBond2010
I've got examples of the main techniques using scripting with ftp.exe here on my site:
http://scripts.dragon-it.co.uk/links/batch-ftp-scripting
Once you have such a batch file you can just use scheduled tasks to run it when you need to.
You would have their end do someting like this in the script
open youripaddress
user username pass
bin
lcd c:\sourcedir\their\end
cd /destdir/your/end
put thefile.txt
quit
Please ask if you want more specifics.
Steve
http://scripts.dragon-it.co.uk/links/batch-ftp-scripting
Once you have such a batch file you can just use scheduled tasks to run it when you need to.
You would have their end do someting like this in the script
open youripaddress
user username pass
bin
lcd c:\sourcedir\their\end
cd /destdir/your/end
put thefile.txt
quit
Please ask if you want more specifics.
Steve
Sorry kdyer, delayed hitting sumbit there and cross posted. I would suggest some of the techniques in my link for keeping the script in the same file can be beneficial especially if it needs copying to multiple machines etc. but all are quite valid ways of course.
ASKER
I need to create the script and then automate the script to run. I have setup the FTP site and it is using a username and password.
ASKER
On the Server I need to send the file from, from notepad I write eg:
open 192.168.1.2
user ftpuser Passw0rd
bin
lcd c:\test.txt
cd /Testfolder/
put test.txt
quit
And I would name the file ftpsend.bat
Is this correct?
open 192.168.1.2
user ftpuser Passw0rd
bin
lcd c:\test.txt
cd /Testfolder/
put test.txt
quit
And I would name the file ftpsend.bat
Is this correct?
Are you needing to create the tasks automatically?
You can use the UI in Windows to do that.. Or, you can use the AT command from the command-line or you can use JT from ftp.microsoft.com and download from there..
ftp://ftp.microsoft.com/ResKit/win2000/jt.zip
HTH,
Kent
You can use the UI in Windows to do that.. Or, you can use the AT command from the command-line or you can use JT from ftp.microsoft.com and download from there..
ftp://ftp.microsoft.com/ResKit/win2000/jt.zip
HTH,
Kent
ASKER
I am on the client's Server. I have create a file called test. Let's my public ip is 203.41.253.67 and the username of my FTP Server is ftpuser and the password is password.
So, can you write the script for me please and then I can use Windows Scheduler to Automate the process.
So, can you write the script for me please and then I can use Windows Scheduler to Automate the process.
ASKER
The file is on the root of the drive on the client's server, and the destination folder on my FTP server is called TestFolder.
You can use your script above with ftp.exe -s and/or build it into one as i suggested above, i.e. something like:
@echo off
REM Save this as FTPUpload.cmd for example
(echo open 192.168.1.2
echo user ftpuser Passw0rd
echo bin
echo lcd c:\test.txt
echo cd /Testfolder/
echo put test.txt
echo quit
) | ftp -n -i
@echo off
REM Save this as FTPUpload.cmd for example
(echo open 192.168.1.2
echo user ftpuser Passw0rd
echo bin
echo lcd c:\test.txt
echo cd /Testfolder/
echo put test.txt
echo quit
) | ftp -n -i
Based on your post inbetween you'd want:
@echo off
REM Save this as FTPUpload.cmd for example
(echo open 203.41.253.67
echo user ftpuser password
echo bin
echo lcd c:\
echo cd /Testfolder/
echo put test.txt
echo quit
) | ftp -n -i
or possibly:
@echo off
REM Save this as FTPUpload.cmd for example
(echo open 203.41.253.67
echo user ftpuser
echo password
echo bin
echo lcd c:\
echo cd /Testfolder/
echo put test.txt
echo quit
) | ftp -n -i
Some want the password on same line, others next.
Steve
@echo off
REM Save this as FTPUpload.cmd for example
(echo open 203.41.253.67
echo user ftpuser password
echo bin
echo lcd c:\
echo cd /Testfolder/
echo put test.txt
echo quit
) | ftp -n -i
or possibly:
@echo off
REM Save this as FTPUpload.cmd for example
(echo open 203.41.253.67
echo user ftpuser
echo password
echo bin
echo lcd c:\
echo cd /Testfolder/
echo put test.txt
echo quit
) | ftp -n -i
Some want the password on same line, others next.
Steve
open 192.168.1.2
user ftpuser Passw0rd
bin
lcd c:\test.txt <----- Bad - trying to change directory to a file
cd /Testfolder/
put test.txt
quit
marked line above should be:
lcd c:\
So using your information provided in I would change it to:
open 203.41.253.67
user ftpuser password
bin
lcd c:\
cd /TestFolder/
put test.txt
quit
user ftpuser Passw0rd
bin
lcd c:\test.txt <----- Bad - trying to change directory to a file
cd /Testfolder/
put test.txt
quit
marked line above should be:
lcd c:\
So using your information provided in I would change it to:
open 203.41.253.67
user ftpuser password
bin
lcd c:\
cd /TestFolder/
put test.txt
quit
lol Steve, you got there before I did as usual.
np, I guess I kinda dived it bit quick after kyder too.
ASKER
I tried this,
@echo off
echo open 192.168.2.2 let say that this is my public ip!
echo user ftpuser Passw0rd1
echo bin
echo lcd c:\test.txt
echo cd /
echo put test.txt
echo quit
I then saved the file a fileupload.cmd to the desktop on the server and ran the file manually by double clicking on it. But the file has not uploaded to my FTP Server. What is going wrong?
@echo off
echo open 192.168.2.2 let say that this is my public ip!
echo user ftpuser Passw0rd1
echo bin
echo lcd c:\test.txt
echo cd /
echo put test.txt
echo quit
I then saved the file a fileupload.cmd to the desktop on the server and ran the file manually by double clicking on it. But the file has not uploaded to my FTP Server. What is going wrong?
OK, try reading my post above please.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Also, you are still using:
echo lcd c:\test.txt
This won't work as you can't change directory to a file.
echo lcd c:\
echo lcd c:\test.txt
This won't work as you can't change directory to a file.
echo lcd c:\
and at the moment are just echoing the details to the screen, not calling ftp.exe at all.
ASKER
@ dragon-it,
Thank you that worked really well. I have tested and it all worked fine. If I may just ask you, I need to then download the file onto one of my client's PC, again an automated which I can use Windows Scheduler. How would the download script be base on the previous information I gave you.
Thank you,
JBond2010
Thank you that worked really well. I have tested and it all worked fine. If I may just ask you, I need to then download the file onto one of my client's PC, again an automated which I can use Windows Scheduler. How would the download script be base on the previous information I gave you.
Thank you,
JBond2010
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Tried that Steve to the download and it worked. Thank you for your help.
No problem, glad we got there!
Steve
Steve
Ftpsend.bat (Note: do not call the script ftp.bat)
Open in new window
Script.s would have:
Open in new window
Then, create a Scheduled Task (in Control Panel, Scheduled Task) in Windows to run the bat file for you..
HTH,
Kent