Solved

Uploading local files to server folders.

Posted on 2007-11-30
12
1,035 Views
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)
  fFTPScript.WriteLine(sFTPScript)
  fFTPScript.Close
  Set fFTPScript = Nothing  
 
  oFTPScriptShell.Run "%comspec% /c FTP -n -s:" & sFTPTempFile & " " & sSite & _
  " > " & sFTPResults
  
  'Response.Write(sFTPTempFile)
  
  Wscript.Sleep 1000
  
  'Check results of transfer.
  Set fFTPResults = oFTPScriptFSO.OpenTextFile(sFTPResults, ForReading, _
  FailIfNotExist, OpenAsDefault)
  sResults = fFTPResults.ReadAll
  fFTPResults.Close
  
  oFTPScriptFSO.DeleteFile(sFTPTempFile)
  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."
  Else
    FTPUpload = "Error: Unknown."
  End If
 
  Set oFTPScriptFSO = Nothing
  Set oFTPScriptShell = Nothing
End Function

Open in new window

0
Comment
Question by:vlad555
  • 7
  • 2
  • 2
  • +1
12 Comments
 
LVL 20

Expert Comment

by:Gawai
ID: 20382504
0
 
LVL 10

Expert Comment

by:dis1931
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?

Regards,

dis1931
0
 

Author Comment

by:vlad555
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,
Vlad
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vlad555
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,
Vlad.
0
 

Author Comment

by:vlad555
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,

Vlad
0
 
LVL 12

Expert Comment

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

regards
Chandru
0
 
LVL 20

Accepted Solution

by:
Gawai earned 500 total points
ID: 20388263
0
 

Author Comment

by:vlad555
ID: 20396577
Hi Gawai,

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

Thanks,
Vlad555
0
 

Author Comment

by:vlad555
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:
(0x80070002)
/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!
0
 

Author Comment

by:vlad555
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:

 
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.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
 
<body>
<%
'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
WScript.Quit
%>
</body>
</html>

Open in new window

0
 
LVL 12

Expert Comment

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

response.write "Hello World"
0
 

Author Closing Comment

by:vlad555
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.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
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…

680 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