Solved

# batch file to upload to ftp

Posted on 2011-10-22
Medium Priority
992 Views
hi All,

i am looking for a good script which i can use to send multiple files to ftp site, i want to schedule the batch file so that it run every night and send files to ftp.

Let me know if i can get it online or if there is someone who have written already
0
Question by:ammartahir1978
• 7
• 6
• 3

LVL 60

Expert Comment

ID: 37012515
Take a look at this question, it has some examples of this. Post back any questions you have from that.

~bp
0

LVL 60

Expert Comment

ID: 37012516
0

Author Comment

ID: 37012598
hi billprew thank you for your reply, but i couldnt understand i tried the first few line and try to connect to ftp server but a window is opening and then close!!!!!
0

Author Comment

ID: 37012603
i am trying this VBS but this doesnt work

anything i am missing in this?
strFTPServer = "IPADDRESS"
Set objNetwork = CreateObject("WScript.Network")
strFolderToCreate = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & "_" & objNetwork.ComputerName

Set objFSO = CreateObject("Scripting.FileSystemObject")
strFTPScript = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "FTPCommands.txt"
Set objFTP = objFSO.CreateTextFile(strFTPScript, True)
objFTP.WriteLine "open " & strFTPServer
objFTP.WriteLine "cd street"
objFTP.WriteLine "cd Windows"
objFTP.WriteLine "md " & strFolderToCreate
objFTP.WriteLine "cd " & strFolderToCreate
objFTP.WriteLine "cd.."
objFTP.WriteLine "cd.."
objFTP.WriteLine "close"
objFTP.WriteLine "bye"
objFTP.Close
strFTPScript = objFSO.GetFile(strFTPScript).ShortPath

Set objShell = CreateObject("WScript.Shell")
objShell.Run "cmd /k ftp -s:" & strFTPScript, 1, True

objFSO.DeleteFile strFTPScript, True

0

LVL 60

Expert Comment

ID: 37012877
Try running the FTP command from a DOS command prompt. Change the vbs script to not delete the temporary file, and then do the following from a command line:

ftp -s:c:\foo\bar.txt

changing c:\foo\bar.txt to your temp file name.  See what errors it displays.

~bp
0

LVL 43

Expert Comment

ID: 37013437

You should be ok with what is in the other q.  my link there describes the other methods i use, though i prefer the one i pasted into the other questions, i.e.

do
cmd.exe
ftp.exe

sort out commands to send to ftp server having logged on, or give us the file / dir names and we can help.

E.g.
Type in at ftp prompt:

open x.x.x.x
cd /remote directory name
bin
put yourfile.txt  (copies yourfile.txt from dir on your sys to remote dir)
quit

When you say multiple, are we talking for or five named files, a directory worth, a directory with sub directories etc?

Steve
0

Author Comment

ID: 37013910
i have tried but it doesnt work?

can someone create the file and i can replace the contents accordingly?

Thank you
0

Author Comment

ID: 37014041
this is what i get when i use this VBS

ftp> open IPADDRESS
220 (vsFTPd 2.2.2)

ftp> cd street
ftp> cd Windows
ftp> md 20111023_SERVER2008
Ambiguous command.
ftp> cd 20111023_SERVER2008
ftp> cd..
Invalid command.
ftp> cd..
Invalid command.
ftp> close
221 Goodbye.

0

LVL 43

Expert Comment

ID: 37014050
Not sure why you are going to VBS route when it is a few lines in batch file, i.e. Copy / paste the code into notepad.  Save as something.cmd (not something.vbs.txt or ftp.cmd for instance as it causes all sorts of issues).

May or not need the user and/or password keyword for your server, I would normally not expect it to need Password, so:

or

Steve
0

LVL 43

Expert Comment

ID: 37014053
Oh and the cd.. commands would have to be cd .. but you don't really need them anyway as you are quitting just after.

Also try to add "-n -i" on the commandline for ftp.exe to stop it doing auto-login, and to stop prompting on some transfers.

i.e.
objShell.Run "cmd /k ftp -n -i -s:" & strFTPScript, 1, True

Steve
0

Author Comment

ID: 37014059
hi dragon-it

thank you so much, yes i would l;ove to use simple scrpt but i tried your provided script and it didnt worked
0

LVL 43

Accepted Solution

Steve Knight earned 2000 total points
ID: 37014097
Ok, it will work if given a chance .... it is the same as you are making a file and then running exactly the same ftp.exe command line.

Either please try suggestions above or feedback on what doesn't work in batch script.  This is what you would need based on your vbscript code in batch IMO:

@echo off
set RemoteDir=street/Windows

REM Get date in form yyyymmdd_computername
echo wscript.echo Year(Date) ^& Right("0" ^& Month(Date), 2) ^& Right("0" ^& Day(Date), 2) ^& "_%computername%" > "%temp%\getdate.vbs
for /f "tokens=*" %%a in ('cscript //nologo "%temp%\getdate.vbs"') do set yyyymmdd=%%a

(echo open %FTPServer%
echo lcd %LocalDir%
echo cd %RemoteDir%
md %yyyymmdd%
cd %yyyymmdd%
echo put "photo3.jpg"
echo quit
) | ftp -n -i
0

LVL 43

Expert Comment

ID: 37014098
This line

may need to be

0

Author Comment

ID: 37014101
thank you dragon it , it is working now

thank you so much for your help
0

Author Closing Comment

ID: 37014103
Excellent
0

LVL 43

Expert Comment

ID: 37014146
No problem, it was probably just that password line.

Steve
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called \$myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
###### Suggested Courses
Course of the Month7 days, 21 hours left to enroll