• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

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
0
James
Asked:
James
  • 10
  • 7
  • 3
  • +1
2 Solutions
 
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 10
  • 7
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now