Link to home
Start Free TrialLog in
Avatar of ammartahir1978
ammartahir1978Flag for United Kingdom of Great Britain and Northern Ireland

asked on

batch file to upload to ftp

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
Avatar of Bill Prew
Bill Prew

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

~bp
Avatar of ammartahir1978

ASKER

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!!!!!
i am trying this VBS but this doesnt work

anything i am missing in this?
strFTPServer = "IPADDRESS"
strUsername = "USERNAME"
strPassword = "PASSWORD"
strFileToUpload = "C:\Users\Administrator\Desktop\photo3.jpg"
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")
strFileToUpload = objFSO.GetFile(strFileToUpload).ShortPath
strFTPScript = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "FTPCommands.txt"
Set objFTP = objFSO.CreateTextFile(strFTPScript, True)
objFTP.WriteLine "open " & strFTPServer
objFTP.WriteLine "user " & strUsername
objFTP.WriteLine "Password " & strPassword
objFTP.WriteLine "cd street"
objFTP.WriteLine "cd Windows"
objFTP.WriteLine "md " & strFolderToCreate
objFTP.WriteLine "cd " & strFolderToCreate
objFTP.WriteLine "put " & strFileToUpload
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

Open in new window

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

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.


http://scripts.dragon-it.co.uk/links/batch-ftp-scripting

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
type in the username and password
lcd c:\dir on your system
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
i have tried but it doesnt work?

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

Thank you
this is what i get when i use this VBS

ftp> open IPADDRESS
Connected to IPADDRESS
220 (vsFTPd 2.2.2)
User (IPADDRESS:(none)):
331 Please specify the password.

530 Login incorrect.
Login failed.
ftp> cd street
530 Please login with USER and PASS.
ftp> cd Windows
530 Please login with USER and PASS.
ftp> md 20111023_SERVER2008
Ambiguous command.
ftp> cd 20111023_SERVER2008
530 Please login with USER and PASS.
ftp> put C:\Users\ADMINI~1\Desktop\photo3.jpg
530 Please login with USER and PASS.
530 Please login with USER and PASS.
ftp> cd..
Invalid command.
ftp> cd..
Invalid command.
ftp> close
221 Goodbye.

Open in new window

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).

Anyway I think the hint in your output may be this "530 Login incorrect." and "530 Please login with USER and PASS."

objFTP.WriteLine "user " & strUsername
objFTP.WriteLine "Password " & strPassword

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

objFTP.WriteLine "user " & strUsername
objFTP.WriteLine strPassword

or

objFTP.WriteLine strUsername
objFTP.WriteLine strPassword



Steve
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
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
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This line

echo user %UserName%

may need to be

echo %UserName%

depending upon your server.
thank you dragon it , it is working now

thank you so much for your help
Excellent
No problem, it was probably just that password line.

Steve