We help IT Professionals succeed at work.

cant get ftp script to work

Medium Priority
625 Views
Last Modified: 2012-05-11
hi i am using the following code for ftp and first of all i am geting the attached image as an error message, and in the log file i get this

lcd "c:\mp3"
open 211.116.164.175 21
user username
password
cd "/mp3"
binary
prompt n
put "20110417110010.mp3"
quit
'------------------------------------------------------------------------------
Const appName = "FTP Upload Utility"
'------------------------------------------------------------------------------

Const Hostname = "211.116.164.175"
Const Port = 21
Const Username = "username"
Const Password = "password"
Const RemoteDir = "/mp3"
Const strExt = "MP3"
Const LocalDir = "c:\mp3"
Const MaxAge = 10

SET objFSO = CreateObject("Scripting.FileSystemObject")

Set ObjFolder = objFSO.GetFolder(LocalDir)
FOR EACH objFile in ObjFolder.Files
  if RIGHT(UCASE(objFile.Path),LEN(strExt)+1) = "." & strExt then
    if datediff("s", objFile.DateLastModified, Now) > 40 Then
      Upload hostname, port, username, password, objFile.Name, localDir, remoteDir
      'objFile.Delete   
    End If
  End If
Next

'------------------------------------------------------------------------------

Sub Upload(hostname, port, username, password, localFile, localDir, remoteDir) 
  Set shell = CreateObject( "WScript.Shell" )
  Set fso = CreateObject("Scripting.FileSystemObject")

  tempDir = shell.ExpandEnvironmentStrings("C:\mp3")
  ' temporary script file supplied to Windows FTP client
  scriptFile = tempDir & "\" & fso.GetTempName
  ' temporary file to store standard output from Windows FTP client
  outputFile = tempDir & "\" & fso.GetTempName


  'input script
  script = script & "lcd " & """" & localDir & """" & vbCRLF
  script = script & "open " & hostname & " " & port & vbCRLF
  script = script & "user " & username & vbCRLF
  script = script & password & vbCRLF
  script = script & "cd " & """" & remoteDir & """" & vbCRLF
  script = script & "binary" & vbCRLF
  script = script & "prompt n" & vbCRLF
  script = script & "put " & """" & localFile & """" & vbCRLF
  script = script & "quit" & vbCRLF

  Set textFile = fso.CreateTextFile(scriptFile, True)
  textFile.WriteLine(script)
  textFile.Close
  Set textFile = Nothing

  ' bWaitOnReturn set to TRUE - indicating script should wait for the program
  ' to finish executing before continuing to the next statement
  shell.Run "%comspec% /c FTP -n -s:" & scriptFile & " > " & outputFile, 0, TRUE
  Wscript.Sleep 500
  ' open standard output temp file read only, failing if not present
  Set textFile = fso.OpenTextFile(outputFile, 1, 0, -2)
  if not textfile.atendofstream then
    results = textFile.ReadAll
  else
    results = ""
  end if
  textFile.Close
  Set textFile = Nothing
  If InStr(results, "550") > 0 And (InStr(results, "226") or Instr(results, "221")) Then
    fso.DeleteFile(scriptFile)
    fso.DeleteFile(outputFile)
    Msg ="WARNING: Could not change to destination directory on host!" & _
      vbCRLF & "File however appears to have been uploaded to default " & _
      "FTP directory associated with user on host."
    MsgBox Msg, vbExclamation, appName

  ElseIf (InStr(results, "226")  or Instr(results, "221")) > 0 Then
    MsgBox "File Uploaded Successfully.", vbInformation, appName
    fso.DeleteFile(scriptFile)
    fso.DeleteFile(outputFile)
  Else
    If InStr(results, "530") > 0 Then
      Msg ="ERROR: Invalid Username/Password"
    ElseIf InStr(results, "550") > 0 Then
      Msg ="ERROR: Could not change to destination directory on host"
    ElseIf InStr(results, "553") > 0 Then
      Msg ="ERROR: Could not create file on host"
    ElseIf InStr(results, "Unknown host") > 0 Then
      Msg ="ERROR: Unknown host"
    ElseIf InStr(results, "File not found") > 0 Then
      Msg ="ERROR: Local File Not Found"
    Else
      Msg ="An ERROR may have occurred."
    End If

    Msg = Msg & _
      vbCRLF & "Script file leveraged: " & scriptFile & _
      vbCRLF & "FTP Output file: " & outputFile & _
      vbCRLF & _
      vbCRLF & "Ensure the above files are manually deleted, as they may " & _
     "contain sensitive information!"
    MsgBox Msg, vbCritical, appName
  End If
  Set shell = Nothing
  Set fso = Nothing
End Sub

Open in new window

ftp.JPG
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
i still am getting the same error messages and wont upload to my ftp server?

am basically looking for a vb script that uploads the mp3s in a certain folder to an ftp directory?
CERTIFIED EXPERT

Commented:
What does c:\mp3\radF5313.tmp contain?

One thing to try is to put the password on the same line as the "user", as:
   script = script & "user " & username & " " & password & vbCRLF
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.