# 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
###### Who is Participating?

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.

IT Security Analyst SeniorCommented:
Do you have the script?

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


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


Then, create a Scheduled Task (in Control Panel, Scheduled Task) in Windows to run the bat file for you..

HTH,

Kent
0
IT ConsultancyCommented:
I've got examples of the main techniques using scripting with ftp.exe here on my site:

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

bin
lcd c:\sourcedir\their\end
cd /destdir/your/end
put thefile.txt
quit

Steve
0
IT 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
Senior 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
Senior 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
IT 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
Senior 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
Senior 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
IT 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
IT 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 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 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
Network 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
bin
lcd c:\
cd /TestFolder/
put test.txt
quit

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

0
IT ConsultancyCommented:
np, I guess I kinda dived it bit quick after kyder too.
0
Senior 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
IT ConsultancyCommented:
0
IT ConsultancyCommented:
i.e.

@echo off
REM Save this as FTPUpload.cmd for example
(echo open 203.41.253.67
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

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

Network 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
IT ConsultancyCommented:
and at the moment are just echoing the details to the screen, not calling ftp.exe at all.
0
Senior 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
IT 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
Senior Cloud Infrastructure EngineerAuthor Commented: