Uploading local files to server folders.

Posted on 2007-11-30
Last Modified: 2010-04-21
I am looking how to upload list of files what I provide with another scripts to the server folders. All paths and filenames I am able to provide for the new uploading code with my previous developed VBscripts. This attached cod is not good for me because WScript.Shell is not working with my system. Need to find completely another solution. Thank you guys!

'	 UPLOAD function for uploading the updated or added images to the server


Function FTPUpload(sSite, sUsername, sPassword, sLocalFile, sRemotePath)

Dim oFTPScriptFSO, oFTPScriptShell, sFTPScript, sFTPTemp, sFTPTempFile, sFTPResults, fFTPScript

  Const OpenAsDefault = -2

  Const FailIfNotExist = 0

  Const ForReading = 1

  Const ForWriting = 2


  Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")

  Set oFTPScriptShell = CreateObject("WScript.Shell")

  sRemotePath = Trim(sRemotePath)

  sLocalFile = Trim(sLocalFile)


  '----------Path Checks---------

  'Here we willcheck the path, if it contains

  'spaces then we need to add quotes to ensure

  'it parses correctly.

  If InStr(sRemotePath, " ") > 0 Then

    If Left(sRemotePath, 1) <> """" And Right(sRemotePath, 1) <> """" Then

      sRemotePath = """" & sRemotePath & """"

    End If

  End If


  If InStr(sLocalFile, " ") > 0 Then

    If Left(sLocalFile, 1) <> """" And Right(sLocalFile, 1) <> """" Then

      sLocalFile = """" & sLocalFile & """"

    End If

  End If

  'Check to ensure that a remote path was

  'passed. If it's blank then pass a "\"

  If Len(sRemotePath) = 0 Then

    'Please note that no premptive checking of the

    'remote path is done. If it does not exist for some

    'reason. Unexpected results may occur.

    sRemotePath = "\"

  End If


  'Check the local path and file to ensure

  'that either the a file that exists was

  'passed or a wildcard was passed.

  If InStr(sLocalFile, "*") Then

    If InStr(sLocalFile, " ") Then

      FTPUpload = "Error: Wildcard uploads do not work if the path contains a " & _

      "space." & vbCRLF

      FTPUpload = FTPUpload & "This is a limitation of the Microsoft FTP client."

      Exit Function

    End If

  ElseIf Len(sLocalFile) = 0 Or Not oFTPScriptFSO.FileExists(sLocalFile) Then

    'nothing to upload

    FTPUpload = "Error: File Not Found."

    Exit Function

  End If

  '--------END Path Checks---------


  'build input file for ftp command

  sFTPScript = sFTPScript & "USER " & sUsername & vbCRLF

  sFTPScript = sFTPScript & sPassword & vbCRLF

  sFTPScript = sFTPScript & "cd " & sRemotePath & vbCRLF

  sFTPScript = sFTPScript & "binary" & vbCRLF

  sFTPScript = sFTPScript & "prompt n" & vbCRLF

  sFTPScript = sFTPScript & "put " & sLocalFile & vbCRLF

  sFTPScript = sFTPScript & "quit" & vbCRLF & "quit" & vbCRLF & "quit" & vbCRLF

  sFTPTemp = oFTPScriptShell.ExpandEnvironmentStrings("%TEMP%")

  sFTPTempFile = sFTPTemp & "\" & oFTPScriptFSO.GetTempName

  sFTPResults = sFTPTemp & "\" & oFTPScriptFSO.GetTempName

  'Write the input file for the ftp command

  'to a temporary file.

  Set fFTPScript = oFTPScriptFSO.CreateTextFile(sFTPTempFile, True)



  Set fFTPScript = Nothing  

  oFTPScriptShell.Run "%comspec% /c FTP -n -s:" & sFTPTempFile & " " & sSite & _

  " > " & sFTPResults




  Wscript.Sleep 1000


  'Check results of transfer.

  Set fFTPResults = oFTPScriptFSO.OpenTextFile(sFTPResults, ForReading, _

  FailIfNotExist, OpenAsDefault)

  sResults = fFTPResults.ReadAll




  oFTPScriptFSO.DeleteFile (sFTPResults)


  If InStr(sResults, "226 Transfer complete.") > 0 Then

    FTPUpload = True

  ElseIf InStr(sResults, "File not found") > 0 Then

    FTPUpload = "Error: File Not Found"

  ElseIf InStr(sResults, "cannot log in.") > 0 Then

    FTPUpload = "Error: Login Failed."


    FTPUpload = "Error: Unknown."

  End If

  Set oFTPScriptFSO = Nothing

  Set oFTPScriptShell = Nothing

End Function

Open in new window

Question by:vlad555
  • 7
  • 2
  • 2
  • +1
LVL 20

Expert Comment

ID: 20382504
LVL 10

Expert Comment

ID: 20382511
Hello vlad555,

What do you mean by is not working?  If you are having issues with Wscript maybe it would be better to fix the issue rather than writing a script for a broken PC.  Any more details?



Author Comment

ID: 20382941
Hallo dis1031, is not supported by IIS version 5.1 This script is not creating the file in TEMP folder.Also i can not use it as a VB Script and when I rename the extension to .aspx it also give me the error. Also in they asking good money what i am unable to pay.

Thank you,

Author Comment

ID: 20382994
Hallo gawai,

Sorry, I didn`t look down on your link. Thank you for the code i will try it and let you know how it works for me.

Thank you,

Author Comment

ID: 20384856
Hallo dis1931,

No, i can not use this script:
because have to buy it. Can someone help me to fix the existing inside my Code Snippet? The first step is to run this part:

Run in a new process:

Set objShell=Wscript.CreateObject("WScript.Shell")
objShell.Run "notepad.exe",3,True
wscript.echo "Now that notepad has closed you can read this"

 - would run and maximize Notepad but would not run the rest of the script until the process has ended.

If I get this to work, hopfully run all other too.

All the best,

LVL 12

Expert Comment

ID: 20386996
Do you want the notepad to close automatically?

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

LVL 20

Accepted Solution

Gawai earned 500 total points
ID: 20388263

Author Comment

ID: 20396577
Hi Gawai,

I need a time to explore all this solutions.  Please be patient and I will give you the answer.


Author Comment

ID: 20398414
The last example fom mr. Gawai: is pretty, alot what can be got to learn but I can not use it here because this scripts need to be on server. In my case I need to upload files from client to server and have controls of server on client site to log in and provide source + destination paths.

I decided to return into the first code snippet in this question to solve the problem I have with WScript.Shell  for which I dont have support on my Internet Information Service Version 5.1. I try to call my snippet function and get the

Error Type:
/05/boss4web/UplTest.asp, line 94

Where line 94 is:   oFTPScriptShell.Run "%cmd% /c FTP -n -s:" & sFTPTempFile & " " & sSite & _
  " > " & sFTPResults

Question - Is my call:  

call FTPUpload("", "some-user", "password", "C:\my\web\som\local\folder\product_picture1.jpg", "som\remote\images\folderl\product_picture1.jpg")

is this call is made right? Why I have this error if its right?

Thank you everyone!

Author Comment

ID: 20398882
Another test I perfomed is in the attached snippet. I uploaded this on my server and tryed to run it there to test shall I have same problem on server or not.  I got the next error:

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'Echo'

/1111.asp, line 14

Error line 14  in snippet is this: WshShell.Echo "Hello World!" 'VBScript
Copy the snippet to the dremveawer or Visula Studio to see better my comments and code.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">



<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">






'WScript object used to create objects

set WshShell = server.CreateObject("WScript.Shell")

'WScript object used to echo information

WshShell.Echo "Hello World!" 'VBScript

'WScript.Echo("Hello World!") 'JScript

'WScript object used to terminate scripts





Open in new window

LVL 12

Expert Comment

ID: 20400370
wshshell.echo doesn't work in ASP you have to write that as

response.write "Hello World"

Author Closing Comment

ID: 31411919
The last link on a solution have alot of useful scripts but it will take few months to complete this way to implement it into my case.

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now