Go Premium for a chance to win a PS4. Enter to Win


Uploading local files to server folders.

Posted on 2007-11-30
Medium Priority
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 Wscript.shell 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,

Wscript.shell 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
http://www.dmxzone.com/ShowDetail.asp?NewsId=12143 they asking good money what i am unable to pay.

Thank you,
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help 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: http://www.dmxzone.com/ShowDetail.asp?NewsId=12143
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?

LVL 20

Accepted Solution

Gawai earned 1500 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: www.motobit.com/help/scptutl/upload.asp 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("sha-lal-llaaa.com", "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" "http://www.w3.org/TR/html4/loose.dtd">
<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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

916 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