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
LVL 15
JamesSenior Cloud Infrastructure EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent DyerIT Security Analyst SeniorCommented:
Do you have the script?

Ftpsend.bat (Note: do not call the script ftp.bat)
ftp -s:script.s

Open in new window


Script.s would have:
open somesite.com
joeblow@site.com
somepassword
cd /pub/secure/etc
send yourfile

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
0
Steve KnightIT ConsultancyCommented:
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
0
Steve KnightIT ConsultancyCommented:
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.
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

JamesSenior Cloud Infrastructure EngineerAuthor Commented:
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.

0
JamesSenior Cloud Infrastructure EngineerAuthor Commented:
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?

0
Kent DyerIT Security Analyst SeniorCommented:
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
0
JamesSenior Cloud Infrastructure EngineerAuthor Commented:
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.
0
JamesSenior Cloud Infrastructure EngineerAuthor Commented:
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.
0
Steve KnightIT ConsultancyCommented:
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
0
Steve KnightIT ConsultancyCommented:
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
0
Steven CarnahanNetwork ManagerCommented:
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

0
Steven CarnahanNetwork ManagerCommented:
lol   Steve,  you got there before I did as usual.  

0
Steve KnightIT ConsultancyCommented:
np, I guess I kinda dived it bit quick after kyder too.
0
JamesSenior Cloud Infrastructure EngineerAuthor Commented:
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?
0
Steve KnightIT ConsultancyCommented:
OK, try reading my post above please.
0
Steve KnightIT ConsultancyCommented:
i.e.

@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
 etc
if you aren't sure start a cmd.exe prompt and type

ftp -n -i
open x.x.x.x
user user pass
etc.

If that works then above script should work.  If it errors then it will tell you why.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steven CarnahanNetwork ManagerCommented:
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:\
0
Steve KnightIT ConsultancyCommented:
and at the moment are just echoing the details to the screen, not calling ftp.exe at all.
0
JamesSenior Cloud Infrastructure EngineerAuthor Commented:
@ 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
0
Steve KnightIT ConsultancyCommented:
difficult to type on mobile but you need to swap paths on cd and lcd lines and use get nstead of put.

Lcd  chooses dir on the machine you are runnning ftp client on and cd command chooses directry on server.  

steve
0
JamesSenior Cloud Infrastructure EngineerAuthor Commented:
Tried that Steve to the download and it worked. Thank you for your help.
0
Steve KnightIT ConsultancyCommented:
No problem, glad we got there!

Steve
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.