Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP 2

Status
Not open for further replies.

NotSQL

Technical User
May 17, 2005
205
0
0
GB
Anyone know any good script to push a file to a FTP Server?


Regards
Dave
 
What have you tried so far ?
As a starting point, open a console window and type ftp -?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Here is some code that has worked for me. It is a rework of something I found here or on the else where. I added drag and drop capability. Hope this helps
Code:
'***************************************************************************
'****Ftp's whatever single file that has been dragged to the script icon****
'****This id for BA OUT ****************************************************
'***************************************************************************

	user = "username"
	pass = "pass"
	ip = "ftpserverIP"
	Set fs = CreateObject("Scripting.FileSystemObject") 'file withthe commands for ftp
	Set objArgs = WScript.Arguments
	if objArgs.Count <> 1 then
		msgbox "Only Single file send. Try again."
	else
		strPath = wscript.ScriptFullName
		name = objArgs(0)
		Set a = fs.CreateTextFile("G:\babar\leifftp.com", True)
		a.WriteLine (user)
		a.WriteLine (pass)
		'a.WriteLine ("bin")
		'a.writeline ("CD 'MAILBOX.PASSAPPL.TD.TDX10CD1'")
		a.WriteLine ("send " & name & " 'MAILBOX.PASSAPPL.TD.TDX10CD1'")
		a.WriteLine ("quit")
		a.Close
	end if
	Set fs = CreateObject("Scripting.FileSystemObject")    'file to run ftp with the commands above
	Set a = fs.CreateTextFile("G:\babar\aaaa.cmd", True)
	a.WriteLine ("ftp -i -s:G:\babar\leifftp.com " & ip)
	a.Close
	WshShell.Run "G:\babar\aaaa.cmd",0,true

Sam
 
Here is a script I like becuase you don't have to use anything external. (ie. ftp.exe)

Hope this helps and provides another good example of file tranfers for you.

[2thumbsup]

Code:
'Option Explicit
'const progname="FTP upload script by Richard Finegold"
'const url = "ftp://ftp.myftpsite.com"
'const rdir = "mydir"
'const user = "anonymous"
'const pass = "myname@mymailsite.com"

'This is an example of ftp'ing without calling the external "FTP" command
'It uses InetCtrls.Inet.1 instead
'Included is a "hint" for simple downloading

'Sources:
'[URL unfurl="true"]http://msdn.microsoft.com/library/partbook/ipwvb5/loggingontoftpserver.htm[/URL]
'[URL unfurl="true"]http://msdn.microsoft.com/library/partbook/egvb6/addinginternettransfercontrol.htm[/URL]
'[URL unfurl="true"]http://cwashington.netreach.net/[/URL] - search on "ftp" - inspiration only!

'Insist on arguments
dim objArgs
Set objArgs = Wscript.Arguments
If 0=objArgs.Count Then
   MsgBox "No files selected for operation!", vbOkOnly + vbCritical, progname
   WScript.Quit
End If


'Force console mode - csforce.vbs (with some reorganization for efficiency)
dim i
if right(ucase(wscript.FullName),11)="WSCRIPT.EXE" then
  dim args, y
  For i = 0 to objArgs.Count - 1
    args = args + " " + objArgs(i)
  Next
  Set y = WScript.CreateObject("WScript.Shell")
  y.Run "cscript.exe " & wscript.ScriptFullName + " " + args, 1
  wscript.quit
end if


'Do actual work
dim fso, ftpo
set fso = WScript.CreateObject("Scripting.FileSystemObject")
set ftpo = WScript.CreateObject("InetCtls.Inet.1")     'Msinet.ocx
ftpo.URL = url
ftpo.UserName = user
ftpo.Password = pass
WScript.Echo "Connecting..."
ftpo.Execute , "CD " & rdir
do
'     WScript.Echo "."
     WScript.Sleep 100     'This can take a while loop while ftpo.StillExecuting


for i = 0 to objArgs.Count - 1
     dim sLFile
     sLFile = objArgs(i)

     if (fso.FileExists(sLFile)) then
          WScript.Echo "Uploading " & sLFile & " as " & FSO.GetFileName(sLFile) & " "
          ftpo.Execute , "Put " & sLFile & " " & FSO.GetFileName(sLFile)
          'ftpo.Execute , "Get " & sRemoteFile & " C:\" & sLFile
          do
          'WScript.Echo "."
               WScript.Sleep 100     'This can take a while
          loop while ftpo.StillExecuting
     else
          MsgBox Chr(34) & sLFile & Chr(34) & " does not exist!", _
           vbOkOnly, progname
     end if
next
WScript.Echo "Closing"
ftpo.Execute , "Close"
WScript.Echo "Done!"

Thanks

John Fuhrman
Titan Global Services
 
not sure why ftp.exe would be considered "external" and Msinet.ocx isn't "external" but i never claimed to know everything. PLease explain.

Sam
 
By external I meant that there is no shell to a command prompt to run an external application.

ie.
Set fs = CreateObject("Scripting.FileSystemObject") 'file to run ftp with the commands above
Set a = fs.CreateTextFile("G:\babar\aaaa.cmd", True)
a.WriteLine ("ftp -i -s:G:\babar\leifftp.com " & ip)
a.Close
[highlight]WshShell.Run "G:\babar\aaaa.cmd",0,true[/highlight]

that's all.


Thanks

John Fuhrman
Titan Global Services
 
OK thanks. Your code is interesting (and functional!) I will add it to my collection I appreciate the explanation.

Sam
 
Hi, dont know if im posting this in the right place but im sure someone will tell me if im not...

Instead of writing it in VBscript, i've written a .bat file

Code:
c:
cd\

echo open ftp.mantruckbus.co.uk > ftptest.txt
echo ddd\dddd >> ftptest.txt
echo ??????? >> ftptest.txt
echo lcd c:\ >> ftptest.txt
echo put zzzuni2man.csv >> ftptest.txt
echo bye >> ftptest.txt


ftp -s:"c:\ftptest.txt"

I know the UserID and password are correct, however it passes back a error message saying incorrect logon..

anyone help?
 
>echo ddd\dddd >> ftptest.txt
Try this instead.
[tt]echo ddd[red]%5C[/red]dddd >> ftptest.txt[/tt]
 
Code:
echo open ftp.mantruckbus.co.uk > ftptest.txt
echo ddd\dddd >> ftptest.txt
echo ??????? >> ftptest.txt
echo lcd c:\ >> ftptest.txt
echo put zzzuni2man.csv >> ftptest.txt
echo bye >> ftptest.txt

The third line of your batch file should contain the password and as written would end with a space.

Try replacing the third line with:

[tt]echo ???????>> ftptest.txt[/tt]


Hope this helps.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top